/** * Change user password only after check old password * * @param string $newPassword New user password * @param string $oldPassword Old user password * * @return bool */ public function chagePassword(string $newPassword, string $oldPassword) : bool { $passUtil = new Password(); $hash = $passUtil->hash($newPassword); if ($passUtil->verify($oldPassword, $this->password)) { $this->password = $hash; return true; } return false; }
/** * Try to log the user passed by param, return true if ok else false * * @param string $user * @param string $password * @param string $storedUser * @param string $storedPassword * @param int $storedId * * @return bool */ public function login(string $user, string $password, string $storedUser = '', string $storedPassword = '', int $storedId = 0) : bool { if ($user !== $storedUser) { return false; } if (!$this->password->verify($password, $storedPassword)) { return false; } $this->sessionInstance->loginTime = time(); $this->sessionInstance->login = ['login' => true, 'user_id' => $storedId, 'user_name' => $storedUser]; $this->sessionInstance->regenerate(); $this->logged = true; return true; }