mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
07fc3650a3
BUGFIX Fixed password hashing design flaw in Security::encrypt_password(). Removing base_convert() packing with unsafe precision, but retaining backwards compatibilty through pluggable encryptors: PasswordEncryptor_LegacyPHPHash (#3004) (merged from r90949) API CHANGE Deprecated Security::encrypt_passwords() (merged from r90949) API CHANGE Deprecated Security::$useSalt, use custom PasswordEncryptor implementation (merged from r90949) API CHANGE Removed Security::get_encryption_algorithms() (merged from r90949) API CHANGE MySQL-specific encyrption types 'password' and 'old_password' are no longer included by default. Use PasswordEncryptor_MySQLPassword and PasswordEncryptor_MySQLOldPassword API CHANGE Built-in number of hashing algorithms has been reduced to 'none', 'md5', 'sha1'. Use PasswordEncryptor::register() and PasswordEncryptor_PHPHash to re-add others. (merged from r90949) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@91576 467b73ca-7a2a-4603-9d3b-597d59a354a9
55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
* Keep track of users' previous passwords, so that we can check that new passwords aren't changed back to old ones.
|
|
* @package sapphire
|
|
* @subpackage security
|
|
*/
|
|
class MemberPassword extends DataObject {
|
|
static $db = array(
|
|
'Password' => 'Varchar',
|
|
'Salt' => 'Varchar',
|
|
'PasswordEncryption' => 'Varchar',
|
|
);
|
|
|
|
static $has_one = array(
|
|
'Member' => 'Member'
|
|
);
|
|
|
|
static $has_many = array();
|
|
|
|
static $many_many = array();
|
|
|
|
static $belongs_many_many = array();
|
|
|
|
/**
|
|
* Log a password change from the given member.
|
|
* Call MemberPassword::log($this) from within Member whenever the password is changed.
|
|
*/
|
|
static function log($member) {
|
|
$record = new MemberPassword();
|
|
$record->MemberID = $member->ID;
|
|
$record->Password = $member->Password;
|
|
$record->PasswordEncryption = $member->PasswordEncryption;
|
|
$record->Salt = $member->Salt;
|
|
$record->write();
|
|
}
|
|
|
|
/**
|
|
* Check if the given password is the same as the one stored in this record.
|
|
* See {@link Member->checkPassword()}.
|
|
*
|
|
* @param String $password Cleartext password
|
|
* @return Boolean
|
|
*/
|
|
function checkPassword($password) {
|
|
$spec = Security::encrypt_password(
|
|
$password,
|
|
$this->Salt,
|
|
$this->PasswordEncryption
|
|
);
|
|
$e = $spec['encryptor'];
|
|
return $e->compare($this->Password, $spec['password']);
|
|
}
|
|
|
|
|
|
} |