function PhpPasswordTest::testPasswordNeedsUpdate

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Password/PhpPasswordTest.php \Drupal\Tests\Core\Password\PhpPasswordTest::testPasswordNeedsUpdate()

Tests a password needs update.

@covers ::hash @covers ::needsRehash

File

core/tests/Drupal/Tests/Core/Password/PhpPasswordTest.php, line 50

Class

PhpPasswordTest
Unit tests for password hashing API.

Namespace

Drupal\Tests\Core\Password

Code

public function testPasswordNeedsUpdate() : void {
    $weakHash = (new PhpPassword(PASSWORD_BCRYPT, [
        'cost' => 4,
    ]))->hash($this->password);
    $this->assertTrue($this->passwordHasher
        ->needsRehash($weakHash), 'Password hash with weak cost settings needs a new hash.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.