@@ -57,4 +57,25 @@ class PasswordHashingTest extends DrupalWebTestCase {
57
57
$this->assertFalse(user_needs_new_hash($account), 'Re-hashed password does not need a new hash.');
58
58
$this->assertTrue(user_check_password($password, $account), 'Password check succeeds with re-hashed password.');
59
59
}
60
+
61
+ /**
62
+ * Verifies that passwords longer than 512 bytes are not hashed.
63
+ */
64
+ public function testLongPassword() {
65
+ $password = str_repeat('x', 512);
66
+ $result = user_hash_password($password);
67
+ $this->assertFalse(empty($result), '512 byte long password is allowed.');
68
+ $password = str_repeat('x', 513);
69
+ $result = user_hash_password($password);
70
+ $this->assertFalse($result, '513 byte long password is not allowed.');
71
+ // Check a string of 3-byte UTF-8 characters.
72
+ $password = str_repeat('€', 170);
73
+ $result = user_hash_password($password);
74
+ $this->assertFalse(empty($result), '510 byte long password is allowed.');
75
+ $password .= 'xx';
76
+ $this->assertFalse(empty($result), '512 byte long password is allowed.');
77
+ $password = str_repeat('€', 171);
78
+ $result = user_hash_password($password);
79
+ $this->assertFalse($result, '513 byte long password is not allowed.');
80
+ }
60
81
}
0 commit comments