1 | <?php |
||
28 | class PasswordHistory extends BaseBlameableModel |
||
29 | { |
||
30 | public $idAttribute = false; |
||
31 | public $updatedAtAttribute = false; |
||
32 | public $updatedByAttribute = false; |
||
33 | public $enableIP = false; |
||
34 | public $contentAttribute = false; |
||
35 | public $passwordHashAttribute = 'pass_hash'; |
||
36 | |||
37 | public static function tableName() |
||
41 | |||
42 | /** |
||
43 | * Validate password. |
||
44 | * |
||
45 | * @param string $password Password or Password Hash. |
||
46 | * @return boolean |
||
47 | */ |
||
48 | public function validatePassword($password) |
||
55 | |||
56 | /** |
||
57 | * Check whether the password has been used. |
||
58 | * @param string $password Password or Password Hash. |
||
59 | * @param User $user |
||
60 | * @return false|static The first validated password model, or false if not validated. |
||
61 | */ |
||
62 | public static function isUsed($password, $user = null) |
||
76 | |||
77 | /** |
||
78 | * Set password. |
||
79 | * @param string $password |
||
80 | */ |
||
81 | public function setPassword($password) |
||
85 | |||
86 | protected static function judgePasswordHash($password) |
||
90 | |||
91 | /** |
||
92 | * Add password to history. |
||
93 | * |
||
94 | * @param string $password Password or Password Hash. |
||
95 | * @param User $user |
||
96 | * @return boolean |
||
97 | * @throws InvalidParamException throw if password existed. |
||
98 | */ |
||
99 | public static function add($password, $user = null) |
||
113 | |||
114 | public static function passHashIsUsed($passHash, $user = null) |
||
128 | |||
129 | public static function addHash($passHash, $user = null) |
||
138 | |||
139 | /** |
||
140 | * Get first password hash. |
||
141 | * |
||
142 | * @param User $user |
||
143 | * @return static |
||
144 | * @throws InvalidParamException throw if user invalid. |
||
145 | */ |
||
146 | public static function first($user = null) |
||
153 | |||
154 | /** |
||
155 | * Get last password hash. |
||
156 | * |
||
157 | * @param User $user |
||
158 | * @return static |
||
159 | * @throws InvalidParamException throw if user invalid. |
||
160 | */ |
||
161 | public static function last($user = null) |
||
168 | } |
||
169 |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: