You are here

public function PasswordHashingTest::providerLongPasswords in Drupal 8

Same name and namespace in other branches
  1. 9 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
Contains \Drupal\Tests\Core\Password\PasswordHashingTest.

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;
}