‪TYPO3CMS  10.4
Md5PasswordHashTest.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 ‪Md5PasswordHashTest extends UnitTestCase
27 {
32  {
33  self::assertNull((new ‪Md5PasswordHash())->getHashedPassword(''));
34  }
35 
40  {
41  self::assertNotNull((new ‪Md5PasswordHash())->getHashedPassword('a'));
42  }
43 
48  {
49  $password = 'password';
50  $subject = new ‪Md5PasswordHash();
51  $saltedHashPassword = $subject->getHashedPassword($password);
52  self::assertTrue($subject->isValidSaltedPW($saltedHashPassword));
53  }
54 
64  {
65  $password = 'password';
66  $saltedHashPassword = '$1$GNu9HdMt$RwkPb28pce4nXZfnplVZY/';
67  self::assertTrue((new ‪Md5PasswordHash())->checkPassword($password, $saltedHashPassword));
68  }
69 
76  {
77  $password = 'password';
78  $saltedHashPassword = '$1$GNu9HdMt$RwkPb28pce4nXZfnplVZY';
79  self::assertFalse((new ‪Md5PasswordHash())->checkPassword($password, $saltedHashPassword));
80  }
81 
91  {
92  $password = 'aEjOtY';
93  $subject = new ‪Md5PasswordHash();
94  $saltedHashPassword = $subject->getHashedPassword($password);
95  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
96  }
97 
107  {
108  $password = '01369';
109  $subject = new ‪Md5PasswordHash();
110  $saltedHashPassword = $subject->getHashedPassword($password);
111  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
112  }
113 
123  {
124  $password = ' !"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~';
125  $subject = new ‪Md5PasswordHash();
126  $saltedHashPassword = $subject->getHashedPassword($password);
127  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
128  }
129 
139  {
140  $password = '';
141  for ($i = 160; $i <= 191; $i++) {
142  $password .= chr($i);
143  }
144  $password .= chr(215) . chr(247);
145  $subject = new ‪Md5PasswordHash();
146  $saltedHashPassword = $subject->getHashedPassword($password);
147  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
148  }
149 
159  {
160  $password = '';
161  for ($i = 192; $i <= 214; $i++) {
162  $password .= chr($i);
163  }
164  for ($i = 216; $i <= 246; $i++) {
165  $password .= chr($i);
166  }
167  for ($i = 248; $i <= 255; $i++) {
168  $password .= chr($i);
169  }
170  $subject = new ‪Md5PasswordHash();
171  $saltedHashPassword = $subject->getHashedPassword($password);
172  self::assertTrue($subject->checkPassword($password, $saltedHashPassword));
173  }
174 
179  {
180  $password = 'password';
181  $password1 = $password . 'INVALID';
182  $subject = new ‪Md5PasswordHash();
183  $saltedHashPassword = $subject->getHashedPassword($password);
184  self::assertFalse($subject->checkPassword($password1, $saltedHashPassword));
185  }
186 
191  {
192  $password = 'password';
193  $subject = new ‪Md5PasswordHash();
194  $saltedHashPassword = $subject->getHashedPassword($password);
195  self::assertFalse($subject->isHashUpdateNeeded($saltedHashPassword));
196  }
197 }
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Md5PasswordHashTest\checkPasswordReturnsTrueWithValidNumericCharClassPassword
‪checkPasswordReturnsTrueWithValidNumericCharClassPassword()
Definition: Md5PasswordHashTest.php:106
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Md5PasswordHashTest\checkPasswordReturnsTrueWithValidAsciiSpecialCharClassPassword
‪checkPasswordReturnsTrueWithValidAsciiSpecialCharClassPassword()
Definition: Md5PasswordHashTest.php:122
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Md5PasswordHashTest\checkPasswordReturnsFalseWithNonValidPassword
‪checkPasswordReturnsFalseWithNonValidPassword()
Definition: Md5PasswordHashTest.php:178
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Md5PasswordHashTest\checkPasswordReturnsTrueWithValidLatin1SpecialCharClassPassword
‪checkPasswordReturnsTrueWithValidLatin1SpecialCharClassPassword()
Definition: Md5PasswordHashTest.php:138
‪TYPO3\CMS\Core\Crypto\PasswordHashing\Md5PasswordHash
Definition: Md5PasswordHash.php:31
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Md5PasswordHashTest\checkPasswordReturnsTrueWithValidAlphaCharClassPassword
‪checkPasswordReturnsTrueWithValidAlphaCharClassPassword()
Definition: Md5PasswordHashTest.php:90
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Md5PasswordHashTest
Definition: Md5PasswordHashTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Md5PasswordHashTest\isHashUpdateNeededReturnsFalse
‪isHashUpdateNeededReturnsFalse()
Definition: Md5PasswordHashTest.php:190
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Md5PasswordHashTest\getHashedPasswordReturnsNotNullWithNonEmptyPassword
‪getHashedPasswordReturnsNotNullWithNonEmptyPassword()
Definition: Md5PasswordHashTest.php:39
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Md5PasswordHashTest\getHashedPasswordCreatesAHashThatValidates
‪getHashedPasswordCreatesAHashThatValidates()
Definition: Md5PasswordHashTest.php:47
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Md5PasswordHashTest\checkPasswordReturnsFalseWithBrokenHash
‪checkPasswordReturnsFalseWithBrokenHash()
Definition: Md5PasswordHashTest.php:75
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Md5PasswordHashTest\checkPasswordReturnsTrueWithValidAlphaCharClassPasswordAndFixedHash
‪checkPasswordReturnsTrueWithValidAlphaCharClassPasswordAndFixedHash()
Definition: Md5PasswordHashTest.php:63
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Md5PasswordHashTest\checkPasswordReturnsTrueWithValidLatin1UmlautCharClassPassword
‪checkPasswordReturnsTrueWithValidLatin1UmlautCharClassPassword()
Definition: Md5PasswordHashTest.php:158
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing\Md5PasswordHashTest\getHashedPasswordReturnsNullWithEmptyPassword
‪getHashedPasswordReturnsNullWithEmptyPassword()
Definition: Md5PasswordHashTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Crypto\PasswordHashing
Definition: Argon2idPasswordHashTest.php:18