‪TYPO3CMS  10.4
PhpassPasswordHashTest.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 ‪PhpassPasswordHashTest extends UnitTestCase
27 {
32  {
33  $this->expectException(\InvalidArgumentException::class);
34  $this->expectExceptionCode(1533940454);
35  new ‪PhpassPasswordHash(['hash_count' => 6]);
36  }
37 
42  {
43  $this->expectException(\InvalidArgumentException::class);
44  $this->expectExceptionCode(1533940454);
45  new ‪PhpassPasswordHash(['hash_count' => 25]);
46  }
47 
52  {
53  $subject = new ‪PhpassPasswordHash(['hash_count' => 7]);
54  self::assertNull($subject->getHashedPassword(''));
55  }
56 
61  {
62  $subject = new ‪PhpassPasswordHash(['hash_count' => 7]);
63  self::assertNotNull($subject->getHashedPassword('a'));
64  }
65 
70  {
71  $password = 'password';
72  $subject = new ‪PhpassPasswordHash(['hash_count' => 7]);
73  $saltedHashPassword = $subject->getHashedPassword($password);
74  self::assertTrue($subject->isValidSaltedPW($saltedHashPassword));
75  }
76 
86  {
87  $password = 'password';
88  $saltedHashPassword = '$P$C7u7E10SBEie/Jbdz0jDtUcWhzgOPF.';
89  $subject = new ‪PhpassPasswordHash(['hash_count' => 7]);
90  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
91  }
92 
99  {
100  $password = 'password';
101  $saltedHashPassword = '$P$C7u7E10SBEie/Jbdz0jDtUcWhzgOPF';
102  $subject = new ‪PhpassPasswordHash(['hash_count' => 7]);
103  self::assertFalse($subject->checkPassword($password, $saltedHashPassword));
104  }
105 
115  {
116  $password = 'aEjOtY';
117  $subject = new ‪PhpassPasswordHash(['hash_count' => 7]);
118  $saltedHashPassword = $subject->getHashedPassword($password);
119  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
120  }
121 
131  {
132  $password = '01369';
133  $subject = new ‪PhpassPasswordHash(['hash_count' => 7]);
134  $saltedHashPassword = $subject->getHashedPassword($password);
135  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
136  }
137 
147  {
148  $password = ' !"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~';
149  $subject = new ‪PhpassPasswordHash(['hash_count' => 7]);
150  $saltedHashPassword = $subject->getHashedPassword($password);
151  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
152  }
153 
163  {
164  $password = '';
165  for ($i = 160; $i <= 191; $i++) {
166  $password .= chr($i);
167  }
168  $password .= chr(215) . chr(247);
169  $subject = new ‪PhpassPasswordHash(['hash_count' => 7]);
170  $saltedHashPassword = $subject->getHashedPassword($password);
171  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
172  }
173 
183  {
184  $password = '';
185  for ($i = 192; $i <= 214; $i++) {
186  $password .= chr($i);
187  }
188  for ($i = 216; $i <= 246; $i++) {
189  $password .= chr($i);
190  }
191  for ($i = 248; $i <= 255; $i++) {
192  $password .= chr($i);
193  }
194  $subject = new ‪PhpassPasswordHash(['hash_count' => 7]);
195  $saltedHashPassword = $subject->getHashedPassword($password);
196  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
197  }
198 
203  {
204  $password = 'password';
205  $password1 = $password . 'INVALID';
206  $subject = new ‪PhpassPasswordHash(['hash_count' => 7]);
207  $saltedHashPassword = $subject->getHashedPassword($password);
208  self::assertFalse($subject->checkPassword($password1, $saltedHashPassword));
209  }
210 
215  {
216  $password = 'password';
217  $subject = new ‪PhpassPasswordHash(['hash_count' => 7]);
218  $saltedHashPassword = $subject->getHashedPassword($password);
219  self::assertFalse($subject->isHashUpdateNeeded($saltedHashPassword));
220  }
221 
226  {
227  $password = 'password';
228  $subject = new ‪PhpassPasswordHash(['hash_count' => 7]);
229  $saltedHashPassword = $subject->getHashedPassword($password);
230  $subject = new ‪PhpassPasswordHash(['hash_count' => 8]);
231  self::assertTrue($subject->isHashUpdateNeeded($saltedHashPassword));
232  }
233 }
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\checkPasswordReturnsFalseWithNonValidPassword
‪checkPasswordReturnsFalseWithNonValidPassword()
Definition: PhpassPasswordHashTest.php:202
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\checkPasswordReturnsTrueWithValidLatin1UmlautCharClassPassword
‪checkPasswordReturnsTrueWithValidLatin1UmlautCharClassPassword()
Definition: PhpassPasswordHashTest.php:182
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\constructorThrowsExceptionIfHashCountIsTooHigh
‪constructorThrowsExceptionIfHashCountIsTooHigh()
Definition: PhpassPasswordHashTest.php:41
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\checkPasswordReturnsFalseWithBrokenHash
‪checkPasswordReturnsFalseWithBrokenHash()
Definition: PhpassPasswordHashTest.php:98
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\getHashedPasswordReturnsNullWithEmptyPassword
‪getHashedPasswordReturnsNullWithEmptyPassword()
Definition: PhpassPasswordHashTest.php:51
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\checkPasswordReturnsTrueWithValidNumericCharClassPassword
‪checkPasswordReturnsTrueWithValidNumericCharClassPassword()
Definition: PhpassPasswordHashTest.php:130
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\checkPasswordReturnsTrueWithValidAsciiSpecialCharClassPassword
‪checkPasswordReturnsTrueWithValidAsciiSpecialCharClassPassword()
Definition: PhpassPasswordHashTest.php:146
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\checkPasswordReturnsTrueWithValidAlphaCharClassPassword
‪checkPasswordReturnsTrueWithValidAlphaCharClassPassword()
Definition: PhpassPasswordHashTest.php:114
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\isHashUpdateNeededReturnsFalseForChangedHashCountSaltedPassword
‪isHashUpdateNeededReturnsFalseForChangedHashCountSaltedPassword()
Definition: PhpassPasswordHashTest.php:225
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\constructorThrowsExceptionIfHashCountIsTooLow
‪constructorThrowsExceptionIfHashCountIsTooLow()
Definition: PhpassPasswordHashTest.php:31
‪TYPO3\CMS\Core\Crypto\PasswordHashing\PhpassPasswordHash
Definition: PhpassPasswordHash.php:35
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\getHashedPasswordValidates
‪getHashedPasswordValidates()
Definition: PhpassPasswordHashTest.php:69
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\checkPasswordReturnsTrueWithValidLatin1SpecialCharClassPassword
‪checkPasswordReturnsTrueWithValidLatin1SpecialCharClassPassword()
Definition: PhpassPasswordHashTest.php:162
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\checkPasswordReturnsTrueWithValidAlphaCharClassPasswordAndFixedHash
‪checkPasswordReturnsTrueWithValidAlphaCharClassPasswordAndFixedHash()
Definition: PhpassPasswordHashTest.php:85
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\isHashUpdateNeededReturnsFalseForValidSaltedPassword
‪isHashUpdateNeededReturnsFalseForValidSaltedPassword()
Definition: PhpassPasswordHashTest.php:214
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest\getHashedPasswordReturnsNotNullWithNotEmptyPassword
‪getHashedPasswordReturnsNotNullWithNotEmptyPassword()
Definition: PhpassPasswordHashTest.php:60
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\PhpassPasswordHashTest
Definition: PhpassPasswordHashTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing
Definition: Argon2idPasswordHashTest.php:18