Version: current

     1 <?php
     2 /**
     3  * Keep track of users' previous passwords, so that we can check that new passwords aren't changed back to old ones.
     4  * @package sapphire
     5  * @subpackage security
     6  */
     7 class MemberPassword extends DataObject {
     8     static $db = array(
     9         'Password' => 'Varchar',
    10         'Salt' => 'Varchar',
    11         'PasswordEncryption' => 'Varchar',
    12     );
    13
    14     static $has_one = array(
    15         'Member' => 'Member'
    16     );
    17
    18     static $has_many = array();
    19
    20     static $many_many = array();
    21
    22     static $belongs_many_many = array();
    23
    24     /**
    25      * Log a password change from the given member.
    26      * Call MemberPassword::log($this) from within Member whenever the password is changed.
    27      */
    28     static function log($member) {
    29         $record = new MemberPassword();
    30         $record->MemberID = $member->ID;
    31         $record->Password = $member->Password;
    32         $record->PasswordEncryption = $member->PasswordEncryption;
    33         $record->Salt = $member->Salt;
    34         $record->write();
    35     }
    36
    37     /**
    38      * Check if the given password is the same as the one stored in this record.
    39      * See {@link Member->checkPassword()}.
    40      *
    41      * @param String $password Cleartext password
    42      * @return Boolean
    43      */
    44     function checkPassword($password) {
    45         $spec = Security::encrypt_password(
    46             $password,
    47             $this->Salt,
    48             $this->PasswordEncryption
    49         );
    50         $e = $spec['encryptor'];
    51         return $e->compare($this->Password, $spec['password']);
    52     }
    53
    54
    55 }

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -