function UserPassRehashTest::testUniqueHashNoPasswordValue

Same name in other branches
  1. 11.x core/modules/user/tests/src/Kernel/UserPassRehashTest.php \Drupal\Tests\user\Kernel\UserPassRehashTest::testUniqueHashNoPasswordValue()

Tests uniqueness of hashes when no password is set.

File

core/modules/user/tests/src/Kernel/UserPassRehashTest.php, line 29

Class

UserPassRehashTest
Tests user_pass_rehash().

Namespace

Drupal\Tests\user\Kernel

Code

public function testUniqueHashNoPasswordValue() : void {
    $this->installEntitySchema('user');
    $timestamp = \Drupal::time()->getRequestTime();
    $user_a = $this->createUser([], NULL, FALSE, [
        'uid' => 12,
        'mail' => '3user@example.com',
        'login' => $timestamp - 1000,
    ]);
    $user_b = $this->createUser([], NULL, FALSE, [
        'uid' => 123,
        'mail' => 'user@example.com',
        'login' => $timestamp - 1000,
    ]);
    // Unset passwords after the users are created in order to avoid
    // (different) password hashes being generated for the empty strings.
    $user_a->setPassword('');
    $user_b->setPassword('');
    $hash_a = user_pass_rehash($user_a, $timestamp);
    $hash_b = user_pass_rehash($user_b, $timestamp);
    $this->assertNotEquals($hash_a, $hash_b);
}

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