function PhpPasswordTest::providerLongPasswords

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

Provides the test matrix for testLongPassword().

File

core/tests/Drupal/Tests/Core/Password/PhpPasswordTest.php, line 109

Class

PhpPasswordTest
Unit tests for password hashing API.

Namespace

Drupal\Tests\Core\Password

Code

public static 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 = (int) 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.