function PasswordHashingTest::testLongPassword

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.php \Drupal\Tests\Core\Password\PasswordHashingTest::testLongPassword()
  2. 8.9.x core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.php \Drupal\Tests\Core\Password\PasswordHashingTest::testLongPassword()

Verifies that passwords longer than 512 bytes are not hashed.

File

modules/simpletest/tests/password.test, line 64

Class

PasswordHashingTest
Unit tests for password hashing API.

Code

public function testLongPassword() {
    $password = str_repeat('x', 512);
    $result = user_hash_password($password);
    $this->assertFalse(empty($result), '512 byte long password is allowed.');
    $password = str_repeat('x', 513);
    $result = user_hash_password($password);
    $this->assertFalse($result, '513 byte long password is not allowed.');
    // Check a string of 3-byte UTF-8 characters.
    $password = str_repeat('€', 170);
    $result = user_hash_password($password);
    $this->assertFalse(empty($result), '510 byte long password is allowed.');
    $password .= 'xx';
    $this->assertFalse(empty($result), '512 byte long password is allowed.');
    $password = str_repeat('€', 171);
    $result = user_hash_password($password);
    $this->assertFalse($result, '513 byte long password is not allowed.');
}

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