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

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

Will use a combination of a random dynamic salt and the given static salt.
public hashPassword ( string $password, string $staticSalt = null ) : string
$password string Cleartext password that should be hashed
$staticSalt string Static salt that will be appended to the random dynamic salt
Результат string A Base64 encoded string with the derived key (hashed password) and dynamic salt
    public function hashPassword($password, $staticSalt = null)
    {
        $dynamicSalt = UtilityAlgorithms::generateRandomBytes($this->dynamicSaltLength);
        $result = CryptographyAlgorithms::pbkdf2($password, $dynamicSalt . $staticSalt, $this->iterationCount, $this->derivedKeyLength, $this->algorithm);
        return base64_encode($dynamicSalt) . ',' . base64_encode($result);
    }

Usage Example

 /**
  * @test
  */
 public function hashAndValidatePasswordWithNotMatchingPasswordOrParametersFails()
 {
     $strategy = new Pbkdf2HashingStrategy(8, 1000, 64, 'sha256');
     $derivedKeyWithSalt = $strategy->hashPassword('password', 'MyStaticSalt');
     $this->assertFalse($strategy->validatePassword('pass', $derivedKeyWithSalt, 'MyStaticSalt'), 'Different password should not match');
     $this->assertFalse($strategy->validatePassword('password', $derivedKeyWithSalt, 'SomeSalt'), 'Different static salt should not match');
     $strategy = new Pbkdf2HashingStrategy(8, 99, 64, 'sha256');
     $this->assertFalse($strategy->validatePassword('password', $derivedKeyWithSalt, 'MyStaticSalt'), 'Different iteration should not match');
 }