added password hashing
This commit is contained in:
		@@ -14,16 +14,31 @@ use App\Enums\UserAuth;
 | 
				
			|||||||
class User
 | 
					class User
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public function __construct(
 | 
					    public function __construct(
 | 
				
			||||||
        private string   $nick = '',
 | 
					        private string          $nick = '',
 | 
				
			||||||
        private string   $password = '',
 | 
					        private string          $password = '',
 | 
				
			||||||
        private string   $first = '',
 | 
					        private readonly string $newPassword = '',
 | 
				
			||||||
        private string   $last = '',
 | 
					        private string          $first = '',
 | 
				
			||||||
        private int      $id = 0,
 | 
					        private string          $last = '',
 | 
				
			||||||
        private bool     $isAdmin = false,
 | 
					        private int             $id = 0,
 | 
				
			||||||
        private UserAuth $userAuth = UserAuth::AUTH_ANONYMOUS
 | 
					        private bool            $isAdmin = false,
 | 
				
			||||||
 | 
					        private UserAuth        $userAuth = UserAuth::AUTH_ANONYMOUS
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // empty body
 | 
					        if (!empty($this->newPassword)) {
 | 
				
			||||||
 | 
					            echo "password";
 | 
				
			||||||
 | 
					            $this->password = password_hash(password: $this->newPassword, algo: PASSWORD_ARGON2I);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (session_status() === PHP_SESSION_ACTIVE) {
 | 
				
			||||||
 | 
					            // ANONYMOUS has id 0
 | 
				
			||||||
 | 
					            if ($this->id != 0) {
 | 
				
			||||||
 | 
					                if ($this->isAdmin) {
 | 
				
			||||||
 | 
					                    $this->userAuth = UserAuth::AUTH_ADMIN;
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    $this->userAuth = UserAuth::AUTH_USER;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function getNick(): string
 | 
					    public function getNick(): string
 | 
				
			||||||
@@ -86,12 +101,12 @@ class User
 | 
				
			|||||||
        $this->isAdmin = $isAdmin;
 | 
					        $this->isAdmin = $isAdmin;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function getAuth()
 | 
					    public function getAuth(): UserAuth
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return UserAuth::AUTH_ANONYMOUS;
 | 
					        return $this->userAuth;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function setAuth(UserAuth $userAuth)
 | 
					    public function setAuth(UserAuth $userAuth): void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->userAuth = $userAuth;
 | 
					        $this->userAuth = $userAuth;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user