mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* @package sapphire
|
||
|
* @subpackage tests
|
||
|
*/
|
||
|
class MemberAuthenticatorTest extends SapphireTest {
|
||
|
function testLegacyPasswordHashMigrationUponLogin() {
|
||
|
$member = new Member();
|
||
|
$member->Email = 'test@test.com';
|
||
|
$member->PasswordEncryption = "sha1";
|
||
|
$member->Password = "mypassword";
|
||
|
$member->write();
|
||
|
|
||
|
$data = array(
|
||
|
'Email' => $member->Email,
|
||
|
'Password' => 'mypassword'
|
||
|
);
|
||
|
MemberAuthenticator::authenticate($data);
|
||
|
|
||
|
$member = DataObject::get_by_id('Member', $member->ID);
|
||
|
$this->assertEquals($member->PasswordEncryption, "sha1_v2.4");
|
||
|
$this->assertTrue($member->checkPassword('mypassword'));
|
||
|
}
|
||
|
|
||
|
function testNoLegacyPasswordHashMigrationOnIncompatibleAlgorithm() {
|
||
|
PasswordEncryptor::register('crc32', 'PasswordEncryptor_PHPHash("crc32")');
|
||
|
|
||
|
$member = new Member();
|
||
|
$member->Email = 'test@test.com';
|
||
|
$member->PasswordEncryption = "crc32";
|
||
|
$member->Password = "mypassword";
|
||
|
$member->write();
|
||
|
|
||
|
$data = array(
|
||
|
'Email' => $member->Email,
|
||
|
'Password' => 'mypassword'
|
||
|
);
|
||
|
MemberAuthenticator::authenticate($data);
|
||
|
|
||
|
$member = DataObject::get_by_id('Member', $member->ID);
|
||
|
$this->assertEquals($member->PasswordEncryption, "crc32");
|
||
|
$this->assertTrue($member->checkPassword('mypassword'));
|
||
|
}
|
||
|
}
|