1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace PhpOffice\Common\Tests\Microsoft;
- use PhpOffice\Common\Microsoft\PasswordEncoder;
- class PasswordEncoderTest extends \PHPUnit\Framework\TestCase
- {
-
- public function testEncodePassword()
- {
-
- $password = 'test';
-
- $hashPassword = PasswordEncoder::hashPassword($password);
-
- $this->assertEquals('M795/MAlmGU8RIsY9Q9uDLHC7bk=', $hashPassword);
- }
-
- public function testEncodePasswordWithSalt()
- {
-
- $password = 'test';
- $salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');
-
- $hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_SHA_1, $salt);
-
- $this->assertEquals('QiDOcpia1YzSVJPiKPwWebl9p/0=', $hashPassword);
- }
-
- public function testDefaultsToSha1IfUnsupportedAlgorithm()
- {
-
- $password = 'test';
- $salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');
-
- $hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_MAC, $salt);
-
- $this->assertEquals('QiDOcpia1YzSVJPiKPwWebl9p/0=', $hashPassword);
- }
-
- public function testEncodePasswordWithNullAsciiCodeInPassword()
- {
-
- $password = 'test' . chr(0);
- $salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');
-
- $hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_MAC, $salt, 1);
-
- $this->assertEquals('rDV9sgdDsztoCQlvRCb1lF2wxNg=', $hashPassword);
- }
- }
|