PhpPassword example

/** * The password hasher under test. */
  protected PasswordInterface $passwordHasher;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->password = $this->randomMachineName();
    $this->passwordHasher = new PhpPassword(PASSWORD_BCRYPT, ['cost' => 5]);
    $this->passwordHash = $this->passwordHasher->hash($this->password);
  }

  /** * Tests a password needs update. * * @covers ::hash * @covers ::needsRehash */
  public function testPasswordNeedsUpdate() {
    $weakHash = (new PhpPassword(PASSWORD_BCRYPT, ['cost' => 4]))->hash($this->password);
    

  public function testLongPassword($password$allowed) {
    // cspell:disable     $bogusHash = '$S$5TOxWPdvJRs0P/xZBdrrPlGgzViOS0drHu3jaIjitesfttrp18bk';
    // cspell:enable
    $passwordService = new PhpassHashedPassword(new PhpPassword());

    if ($allowed) {
      $hash = $passwordService->hash($password);
      $this->assertNotFalse($hash);
      $result = $passwordService->check($password$hash);
      $this->assertTrue($result);
    }
    else {
      $result = $passwordService->check($password$bogusHash);
      $this->assertFalse($result);
    }
  }
Home | Imprint | This part of the site doesn't use cookies.