2008-04-26 08:31:52 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Keep track of users' previous passwords, so that we can check that new passwords aren't changed back to old ones.
|
2008-06-15 15:33:53 +02:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage security
|
2008-04-26 08:31:52 +02:00
|
|
|
*/
|
|
|
|
class MemberPassword extends DataObject {
|
|
|
|
static $db = array(
|
|
|
|
'Password' => 'Varchar',
|
|
|
|
'Salt' => 'Varchar',
|
|
|
|
'PasswordEncryption' => 'Varchar',
|
|
|
|
);
|
|
|
|
|
|
|
|
static $has_one = array(
|
2009-02-02 00:49:53 +01:00
|
|
|
'Member' => 'Member'
|
2008-04-26 08:31:52 +02:00
|
|
|
);
|
|
|
|
|
2009-02-02 00:49:53 +01:00
|
|
|
static $has_many = array();
|
|
|
|
|
|
|
|
static $many_many = array();
|
|
|
|
|
|
|
|
static $belongs_many_many = array();
|
|
|
|
|
2008-04-26 08:31:52 +02:00
|
|
|
/**
|
|
|
|
* 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']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|