silverstripe-framework/security/MemberPassword.php
Sam Minnee eb60b67732 Merged revisions 52121 via svnmerge from
http://svn.silverstripe.com/open/modules/sapphire/branches/govtsecurity

........
  r52121 | sminnee | 2008-04-03 22:04:33 +1300 (Thu, 03 Apr 2008) | 4 lines
  
  Added DataObject::validate() for specifying DataObject-level validators.
  Added DataObject::onAfterWrite(), a complement of DataObject::onBeforeWrite()
  Added password strength testing to security system
  Added password expiry to security system
........


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@53465 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-04-26 06:31:52 +00:00

39 lines
1.0 KiB
PHP

<?php
/**
* Keep track of users' previous passwords, so that we can check that new passwords aren't changed back to old ones.
*/
class MemberPassword extends DataObject {
static $db = array(
'Password' => 'Varchar',
'Salt' => 'Varchar',
'PasswordEncryption' => 'Varchar',
);
static $has_one = array(
'Member' => 'Member',
);
/**
* 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
*/
function checkPassword($password) {
$encryption_details = Security::encrypt_password($password, $this->Salt, $this->PasswordEncryption);
return ($this->Password === $encryption_details['password']);
}
}