silverstripe-framework/Security/MemberPassword.php

58 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2016-06-23 01:37:22 +02:00
namespace SilverStripe\Security;
use SilverStripe\ORM\DataObject;
2016-06-23 01:37:22 +02:00
/**
* Keep track of users' previous passwords, so that we can check that new passwords aren't changed back to old ones.
*
* @property string Password
* @property string Salt
* @property string PasswordEncryption
* @property int MemberID ID of the Member
* @method Member Member() Owner of the password
*/
class MemberPassword extends DataObject {
private static $db = array(
'Password' => 'Varchar(160)',
'Salt' => 'Varchar(50)',
'PasswordEncryption' => 'Varchar(50)',
);
2014-08-15 08:53:05 +02:00
private static $has_one = array(
2016-06-23 01:37:22 +02:00
'Member' => 'SilverStripe\\Security\\Member'
);
2016-06-23 01:37:22 +02:00
private static $table_name = "MemberPassword";
2014-08-15 08:53:05 +02:00
/**
* Log a password change from the given member.
* Call MemberPassword::log($this) from within Member whenever the password is changed.
2016-06-23 01:37:22 +02:00
*
* @param Member $member
*/
public 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();
}
2014-08-15 08:53:05 +02:00
/**
* Check if the given password is the same as the one stored in this record.
* See {@link Member->checkPassword()}.
2014-08-15 08:53:05 +02:00
*
* @param String $password Cleartext password
* @return Boolean
2014-08-15 08:53:05 +02:00
*/
public function checkPassword($password) {
$e = PasswordEncryptor::create_for_algorithm($this->PasswordEncryption);
return $e->check($this->Password, $password, $this->Salt, $this->Member());
}
2014-08-15 08:53:05 +02:00
}