Nette\Security\Passwords::hash PHP Метод

hash() публичный статический Метод

Computes salted password hash.
public static hash ( $password, array $options = [] ) : string
$options array
Результат string 60 chars long
    public static function hash($password, array $options = [])
    {
        if (isset($options['cost']) && ($options['cost'] < 4 || $options['cost'] > 31)) {
            throw new Nette\InvalidArgumentException("Cost must be in range 4-31, {$options['cost']} given.");
        }
        $hash = password_hash($password, PASSWORD_BCRYPT, $options);
        if ($hash === FALSE || strlen($hash) < 60) {
            throw new Nette\InvalidStateException('Hash computed by password_hash is invalid.');
        }
        return $hash;
    }

Usage Example

Пример #1
0
 /**
  * Adds new user.
  * @param  string
  * @param  string
  * @return void
  */
 public function add($username, $password)
 {
     $user = new Entities\UserEntity();
     $user->setUsername($username);
     $user->setPassword(Passwords::hash($password));
     $this->userRepository->save($user);
 }
All Usage Examples Of Nette\Security\Passwords::hash