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.
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-06-15 15:33:53 +02:00
|
|
|
* @subpackage security
|
2008-04-26 08:31:52 +02:00
|
|
|
*/
|
|
|
|
class MemberPassword extends DataObject {
|
|
|
|
static $db = array(
|
2012-05-07 04:18:15 +02:00
|
|
|
'Password' => 'Varchar(160)',
|
|
|
|
'Salt' => 'Varchar(50)',
|
|
|
|
'PasswordEncryption' => 'Varchar(50)',
|
2008-04-26 08:31:52 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function log($member) {
|
2008-04-26 08:31:52 +02:00
|
|
|
$record = new MemberPassword();
|
|
|
|
$record->MemberID = $member->ID;
|
|
|
|
$record->Password = $member->Password;
|
|
|
|
$record->PasswordEncryption = $member->PasswordEncryption;
|
|
|
|
$record->Salt = $member->Salt;
|
|
|
|
$record->write();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-06 03:23:21 +01:00
|
|
|
* 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
|
2008-04-26 08:31:52 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function checkPassword($password) {
|
2012-05-07 05:03:53 +02:00
|
|
|
$e = PasswordEncryptor::create_for_algorithm($this->PasswordEncryption);
|
|
|
|
return $e->check($this->Password, $password, $this->Salt, $this->Member());
|
2008-04-26 08:31:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|