‪TYPO3CMS  10.4
Pbkdf2PasswordHashTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪Pbkdf2PasswordHashTest extends UnitTestCase
27 {
32  {
33  $this->expectException(\InvalidArgumentException::class);
34  $this->expectExceptionCode(1533903544);
35  new ‪Pbkdf2PasswordHash(['hash_count' => 999]);
36  }
37 
42  {
43  $this->expectException(\InvalidArgumentException::class);
44  $this->expectExceptionCode(1533903544);
45  new ‪Pbkdf2PasswordHash(['hash_count' => 10000001]);
46  }
47 
52  {
53  $password = '';
54  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1000]);
55  self::assertNull($subject->getHashedPassword($password));
56  }
57 
62  {
63  $password = 'a';
64  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1000]);
65  self::assertNotNull($subject->getHashedPassword($password));
66  }
67 
72  {
73  $password = 'password';
74  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1000]);
75  $saltedHashPassword = $subject->getHashedPassword($password);
76  self::assertTrue($subject->isValidSaltedPW($saltedHashPassword));
77  }
78 
88  {
89  $password = 'password';
90  $saltedHashPassword = '$pbkdf2-sha256$1000$woPhT0yoWm3AXJXSjuxJ3w$iZ6EvTulMqXlzr0NO8z5EyrklFcJk5Uw2Fqje68FfaQ';
91  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1000]);
92  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
93  }
94 
101  {
102  $password = 'password';
103  $saltedHashPassword = '$pbkdf2-sha256$1000$woPhT0yoWm3AXJXSjuxJ3w$iZ6EvTulMqXlzr0NO8z5EyrklFcJk5Uw2Fqje68Ffa';
104  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1000]);
105  self::assertFalse($subject->checkPassword($password, $saltedHashPassword));
106  }
107 
117  {
118  $password = 'aEjOtY';
119  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1000]);
120  $saltedHashPassword = $subject->getHashedPassword($password);
121  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
122  }
123 
133  {
134  $password = '01369';
135  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1000]);
136  $saltedHashPassword = $subject->getHashedPassword($password);
137  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
138  }
139 
149  {
150  $password = ' !"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~';
151  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1000]);
152  $saltedHashPassword = $subject->getHashedPassword($password);
153  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
154  }
155 
165  {
166  $password = '';
167  for ($i = 160; $i <= 191; $i++) {
168  $password .= chr($i);
169  }
170  $password .= chr(215) . chr(247);
171  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1000]);
172  $saltedHashPassword = $subject->getHashedPassword($password);
173  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
174  }
175 
185  {
186  $password = '';
187  for ($i = 192; $i <= 214; $i++) {
188  $password .= chr($i);
189  }
190  for ($i = 216; $i <= 246; $i++) {
191  $password .= chr($i);
192  }
193  for ($i = 248; $i <= 255; $i++) {
194  $password .= chr($i);
195  }
196  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1000]);
197  $saltedHashPassword = $subject->getHashedPassword($password);
198  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
199  }
200 
205  {
206  $password = 'password';
207  $password1 = $password . 'INVALID';
208  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1000]);
209  $saltedHashPassword = $subject->getHashedPassword($password);
210  self::assertFalse($subject->checkPassword($password1, $saltedHashPassword));
211  }
212 
217  {
218  $password = 'password';
219  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1000]);
220  $saltedHashPassword = $subject->getHashedPassword($password);
221  self::assertFalse($subject->isHashUpdateNeeded($saltedHashPassword));
222  }
223 
228  {
229  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1000]);
230  $saltedHashPassword = $subject->getHashedPassword('password');
231  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1001]);
232  self::assertTrue($subject->isHashUpdateNeeded($saltedHashPassword));
233  }
234 
239  {
240  $passlibSaltedHash= '$pbkdf2-sha256$6400$.6UI/S.nXIk8jcbdHx3Fhg$98jZicV16ODfEsEZeYPGHU3kbrUrvUEXOPimVSQDD44';
241  $subject = new ‪Pbkdf2PasswordHash(['hash_count' => 1000]);
242  self::assertTrue($subject->checkPassword('password', $passlibSaltedHash));
243  }
244 }
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\checkPasswordReturnsTrueWithValidAlphaCharClassPasswordAndFixedHash
‪checkPasswordReturnsTrueWithValidAlphaCharClassPasswordAndFixedHash()
Definition: Pbkdf2PasswordHashTest.php:87
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest
Definition: Pbkdf2PasswordHashTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\checkPasswordReturnsFalseWithBrokenHash
‪checkPasswordReturnsFalseWithBrokenHash()
Definition: Pbkdf2PasswordHashTest.php:100
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\constructorThrowsExceptionIfHashCountIsTooHigh
‪constructorThrowsExceptionIfHashCountIsTooHigh()
Definition: Pbkdf2PasswordHashTest.php:41
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\checkPasswordReturnsTrueWithValidLatin1UmlautCharClassPassword
‪checkPasswordReturnsTrueWithValidLatin1UmlautCharClassPassword()
Definition: Pbkdf2PasswordHashTest.php:184
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\checkPasswordReturnsTrueWithValidAsciiSpecialCharClassPassword
‪checkPasswordReturnsTrueWithValidAsciiSpecialCharClassPassword()
Definition: Pbkdf2PasswordHashTest.php:148
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\checkPasswordReturnsTrueWithValidAlphaCharClassPassword
‪checkPasswordReturnsTrueWithValidAlphaCharClassPassword()
Definition: Pbkdf2PasswordHashTest.php:116
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\isHashUpdateNeededReturnsFalseForValidSaltedPassword
‪isHashUpdateNeededReturnsFalseForValidSaltedPassword()
Definition: Pbkdf2PasswordHashTest.php:216
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\checkPasswordReturnsTrueWithValidNumericCharClassPassword
‪checkPasswordReturnsTrueWithValidNumericCharClassPassword()
Definition: Pbkdf2PasswordHashTest.php:132
‪TYPO3\CMS\Core\Crypto\PasswordHashing\Pbkdf2PasswordHash
Definition: Pbkdf2PasswordHash.php:28
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\getHashedPasswordReturnsNotNullWithNullPassword
‪getHashedPasswordReturnsNotNullWithNullPassword()
Definition: Pbkdf2PasswordHashTest.php:61
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\checkPasswordReturnsFalseWithNonValidPassword
‪checkPasswordReturnsFalseWithNonValidPassword()
Definition: Pbkdf2PasswordHashTest.php:204
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\getHashedPasswordValidates
‪getHashedPasswordValidates()
Definition: Pbkdf2PasswordHashTest.php:71
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\checkPasswordIsCompatibleWithPythonPasslibHashes
‪checkPasswordIsCompatibleWithPythonPasslibHashes()
Definition: Pbkdf2PasswordHashTest.php:238
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\constructorThrowsExceptionIfHashCountIsTooLow
‪constructorThrowsExceptionIfHashCountIsTooLow()
Definition: Pbkdf2PasswordHashTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\isHashUpdateNeededReturnsTrueWithChangedHashCount
‪isHashUpdateNeededReturnsTrueWithChangedHashCount()
Definition: Pbkdf2PasswordHashTest.php:227
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\checkPasswordReturnsTrueWithValidLatin1SpecialCharClassPassword
‪checkPasswordReturnsTrueWithValidLatin1SpecialCharClassPassword()
Definition: Pbkdf2PasswordHashTest.php:164
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Pbkdf2PasswordHashTest\getHashedPasswordReturnsNullWithEmptyPassword
‪getHashedPasswordReturnsNullWithEmptyPassword()
Definition: Pbkdf2PasswordHashTest.php:51
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing
Definition: Argon2idPasswordHashTest.php:18