function LegacyPasswordHashingTest::testPasswordHashing

Same name in other branches
  1. 10 core/modules/phpass/tests/src/Unit/LegacyPasswordHashingTest.php \Drupal\Tests\phpass\Unit\LegacyPasswordHashingTest::testPasswordHashing()

Tests password hashing.

@covers ::hash @covers ::getCountLog2 @covers ::base64Encode @covers ::check @covers ::generateSalt @covers ::needsRehash

File

core/modules/phpass/tests/src/Unit/LegacyPasswordHashingTest.php, line 85

Class

LegacyPasswordHashingTest
Unit tests for password hashing API.

Namespace

Drupal\Tests\phpass\Unit

Code

public function testPasswordHashing() {
    $this->assertSame(PhpassHashedPassword::MIN_HASH_COUNT, $this->passwordHasher
        ->getCountLog2($this->hashedPassword), 'Hashed password has the minimum number of log2 iterations.');
    $this->assertNotEquals($this->hashedPassword, $this->md5HashedPassword, 'Password hashes not the same.');
    $this->assertTrue($this->passwordHasher
        ->check($this->password, $this->md5HashedPassword), 'Password check succeeds.');
    $this->assertTrue($this->passwordHasher
        ->check($this->password, $this->hashedPassword), 'Password check succeeds.');
    // Since the log2 setting hasn't changed and the user has a valid password,
    // userNeedsNewHash() should return FALSE.
    $this->assertFalse($this->passwordHasher
        ->needsRehash($this->hashedPassword), 'Does not need a new hash.');
}

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