PhpassHashedPassword example


  public function testPasswordHash() {
    $samplePassword = $this->randomMachineName();
    $sampleHash = $this->randomMachineName();

    $corePassword = $this->prophesize(PasswordInterface::class);
    $corePassword->hash($samplePassword)->willReturn($sampleHash);

    $passwordService = new PhpassHashedPassword($corePassword->reveal());
    $result = $passwordService->hash($samplePassword);

    $this->assertSame($sampleHash$result, 'Calls to hash() are forwarded to core password service.');
  }

  /** * Tests that needsRehash() is forwarded to corePassword instance. * * @covers ::needsRehash */
  public function testPasswordNeedsRehash() {
    

  protected $passwordHasher;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->expectDeprecation('Calling Drupal\Core\Password\PhpassHashedPasswordBase::__construct() with numeric $countLog2 as the first parameter is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use PhpassHashedPasswordInterface::__construct() with $corePassword parameter set to an instance of Drupal\Core\Password\PhpPassword instead. See https://www.drupal.org/node/3322420');
    $this->password = $this->randomMachineName();
    $this->passwordHasher = new PhpassHashedPassword(1);
    $this->hashedPassword = $this->passwordHasher->hash($this->password);
    $this->md5HashedPassword = 'U' . $this->passwordHasher->hash(md5($this->password));
  }

  /** * Tests invalid constructor arguments. */
  public function testInvalidArguments() {
    $this->expectException(\InvalidArgumentException::class);
    new PhpassHashedPassword('not a number');
  }

  

class PasswordHashingLegacyTest extends UnitTestCase {

  /** * @covers \Drupal\Core\Password\PhpassHashedPassword */
  public function testDeprecation() {
    $this->expectDeprecation('\Drupal\Core\Password\PhpassHashedPassword is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. The password compatibility service has been moved to the phpass module. Use \Drupal\phpass\Password\PhpassHashedPassword instead. See https://www.drupal.org/node/3322420');
    $this->expectDeprecation('Calling Drupal\Core\Password\PhpassHashedPasswordBase::__construct() with numeric $countLog2 as the first parameter is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use PhpassHashedPasswordInterface::__construct() with $corePassword parameter set to an instance of Drupal\Core\Password\PhpPassword instead. See https://www.drupal.org/node/3322420');
    $passwordService = new PhpassHashedPassword(4);
    $this->assertInstanceOf(PhpassHashedPassword::class$passwordService);
  }

}
Home | Imprint | This part of the site doesn't use cookies.