Neos\Flow\Security\Cryptography\BCryptHashingStrategy::hashPassword PHP Метод

hashPassword() публичный Метод

Creates a BCrypt hash
public hashPassword ( string $password, string $staticSalt = null ) : string
$password string The plaintext password to hash
$staticSalt string Optional static salt that will not be stored in the hashed password
Результат string the result of the crypt() call
    public function hashPassword($password, $staticSalt = null)
    {
        $dynamicSalt = UtilityAlgorithms::generateRandomString(22, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./');
        return crypt($password, '$2a$' . $this->cost . '$' . $dynamicSalt);
    }

Usage Example

 /**
  * @test
  */
 public function hashAndValidatePasswordWithDifferentCostsMatch()
 {
     $strategy = new BCryptHashingStrategy(10);
     $otherStrategy = new BCryptHashingStrategy(6);
     $derivedKeyWithSalt = $otherStrategy->hashPassword('password');
     $this->assertTrue($strategy->validatePassword('password', $derivedKeyWithSalt), 'Hashing strategy should validate password with different cost');
 }