Exemple #1
0
 public function changePassword($userId, $oldPassword, $newPassword)
 {
     $oldPassword = self::removeCapsLock($oldPassword);
     $newPassword = self::removeCapsLock($newPassword);
     $row = $this->database->table(self::TABLE_NAME)->where(self::COLUMN_ID, $userId)->fetch();
     if (!$row) {
         throw new Nette\Security\AuthenticationException('Při změně hesla došlo k chybě.', self::IDENTITY_NOT_FOUND);
     } elseif (!Passwords::verify($oldPassword, $row[self::COLUMN_PASSWORD_HASH])) {
         throw new Nette\Security\AuthenticationException('Zadané staré heslo je neplatné.', self::INVALID_CREDENTIAL);
     } elseif (Passwords::needsRehash($row[self::COLUMN_PASSWORD_HASH])) {
         $row->update(array(self::COLUMN_PASSWORD_HASH => Passwords::hash($oldPassword)));
     }
     $row->update(array(self::COLUMN_PASSWORD_HASH => Passwords::hash($newPassword)));
 }
Exemple #2
0
 public function changePassword($id, $password)
 {
     return $this->getUser($id)->update([self::COLUMN_PASSWORD_HASH => Passwords::hash($password)]);
 }
Exemple #3
0
 /**
  * Adds new user.
  * @param  string
  * @param  string
  * @return void
  */
 public function add($username, $password)
 {
     $this->database->table(self::TABLE_NAME)->insert(array(self::COLUMN_NAME => $username, self::COLUMN_PASSWORD_HASH => Passwords::hash($password)));
 }