function PasswordHashingTest::providerLongPasswords

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

Provides the test matrix for testLongPassword().

File

core/tests/Drupal/Tests/Core/Password/PasswordHashingTest.php, line 152

Class

PasswordHashingTest
Unit tests for password hashing API.

Namespace

Drupal\Tests\Core\Password

Code

public function providerLongPasswords() {
    // '512 byte long password is allowed.'
    $passwords['allowed'] = [
        str_repeat('x', PasswordInterface::PASSWORD_MAX_LENGTH),
        TRUE,
    ];
    // 513 byte long password is not allowed.
    $passwords['too_long'] = [
        str_repeat('x', PasswordInterface::PASSWORD_MAX_LENGTH + 1),
        FALSE,
    ];
    // Check a string of 3-byte UTF-8 characters, 510 byte long password is
    // allowed.
    $len = floor(PasswordInterface::PASSWORD_MAX_LENGTH / 3);
    $diff = PasswordInterface::PASSWORD_MAX_LENGTH % 3;
    $passwords['utf8'] = [
        str_repeat('€', $len),
        TRUE,
    ];
    // 512 byte long password is allowed.
    $passwords['ut8_extended'] = [
        $passwords['utf8'][0] . str_repeat('x', $diff),
        TRUE,
    ];
    // Check a string of 3-byte UTF-8 characters, 513 byte long password is
    // allowed.
    $passwords['utf8_too_long'] = [
        str_repeat('€', $len + 1),
        FALSE,
    ];
    return $passwords;
}

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