function PasswordVerifyTest::testPasswordCheckSupported

Same name in other branches
  1. 11.x core/modules/phpass/tests/src/Unit/PasswordVerifyTest.php \Drupal\Tests\phpass\Unit\PasswordVerifyTest::testPasswordCheckSupported()

Tests that check() verifies passwords if hash settings are supported.

@covers ::check @covers ::crypt @covers ::getCountLog2 @covers ::enforceLog2Boundaries @covers ::base64Encode

File

core/modules/phpass/tests/src/Unit/PasswordVerifyTest.php, line 80

Class

PasswordVerifyTest
Unit tests for password hashing API.

Namespace

Drupal\Tests\phpass\Unit

Code

public function testPasswordCheckSupported() : void {
    $validPassword = 'valid password';
    // cspell:disable
    $passwordHash = '$S$5TOxWPdvJRs0P/xZBdrrPlGgzViOS0drHu3jaIjitesfttrp18bk';
    $passwordLayered = 'U$S$5vNHDQyLqCTvsYBLWBUWXJWhA0m3DTpBh04acFEOGB.bKBclhKgo';
    // cspell:enable
    $invalidPassword = 'invalid password';
    $corePassword = $this->prophesize(PasswordInterface::class);
    $corePassword->check()
        ->shouldNotBeCalled();
    $passwordService = new PhpassHashedPassword($corePassword->reveal());
    $result = $passwordService->check($validPassword, $passwordHash);
    $this->assertTrue($result, 'Accepts valid passwords created prior to 10.1.x');
    $result = $passwordService->check($invalidPassword, $passwordHash);
    $this->assertFalse($result, 'Rejects invalid passwords created prior to 10.1.x');
    $result = $passwordService->check($validPassword, $passwordLayered);
    $this->assertTrue($result, 'Accepts valid passwords migrated from sites running 6.x');
    $result = $passwordService->check($invalidPassword, $passwordLayered);
    $this->assertFalse($result, 'Rejects invalid passwords migrated from sites running 6.x');
}

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