function PasswordVerifyTest::providerLongPasswords

Same name in other branches
  1. 11.x core/modules/phpass/tests/src/Unit/PasswordVerifyTest.php \Drupal\Tests\phpass\Unit\PasswordVerifyTest::providerLongPasswords()

Provides the test matrix for testLongPassword().

File

core/modules/phpass/tests/src/Unit/PasswordVerifyTest.php, line 146

Class

PasswordVerifyTest
Unit tests for password hashing API.

Namespace

Drupal\Tests\phpass\Unit

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.