You are here

public function PasswordHashingTest::providerLongPasswords in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 153
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'] = array(
    str_repeat('x', PasswordInterface::PASSWORD_MAX_LENGTH),
    TRUE,
  );

  // 513 byte long password is not allowed.
  $passwords['too_long'] = array(
    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'] = array(
    str_repeat('€', $len),
    TRUE,
  );

  // 512 byte long password is allowed.
  $passwords['ut8_extended'] = array(
    $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'] = array(
    str_repeat('€', $len + 1),
    FALSE,
  );
  return $passwords;
}