1 | <?php |
||
26 | trait UserPasswordHistoryTrait |
||
27 | { |
||
28 | /** |
||
29 | * @var string|false Password History class name. If you do not need password |
||
30 | * history model, please set it false. |
||
31 | */ |
||
32 | public $passwordHistoryClass = false; |
||
33 | |||
34 | /** |
||
35 | * @var boolean determine whether to allow the password that has been used to be stored. |
||
36 | */ |
||
37 | public $allowUsedPassword = true; |
||
38 | |||
39 | /** |
||
40 | * Get all password histories sorted by creation time in descending order. |
||
41 | * @return boolean|PasswordHistory[] False if password history class is invalid. |
||
42 | */ |
||
43 | 7 | public function getPasswordHistories() |
|
51 | |||
52 | /** |
||
53 | * This event is ONLY used for adding password to history. |
||
54 | * You SHOULD NOT call this method directly, or you know the consequences of doing so |
||
55 | * @param ModelEvent $event |
||
56 | * @return boolean False if no password was added to history. |
||
57 | */ |
||
58 | 46 | public function onAddPasswordToHistory($event) |
|
81 | |||
82 | /** |
||
83 | * Add password to history. |
||
84 | * Note: Please specify password history class before using this method. |
||
85 | * |
||
86 | * @param string $password the password to be added. |
||
87 | * @return boolean whether the password added. False if password history class not specified. |
||
88 | * @throws InvalidParamException throw if password existed. |
||
89 | */ |
||
90 | 3 | public function addPasswordHistory($password) |
|
98 | |||
99 | /** |
||
100 | * Add password hash to history. |
||
101 | * Note: Please specify password history class before using this method. |
||
102 | * |
||
103 | * @param string $passHash Password hash to be added. |
||
104 | * @return boolean whether the password hash added. False if password history class not specified. |
||
105 | * @throws InvalidParamException throw if password existed. |
||
106 | */ |
||
107 | 2 | public function addPasswordHashToHistory($passHash) |
|
115 | |||
116 | /** |
||
117 | * @inheritdoc |
||
118 | */ |
||
119 | 46 | public function getPasswordHashRules() |
|
133 | |||
134 | /** |
||
135 | * @var string The message for password used error. |
||
136 | */ |
||
137 | public $passwordUsedMessage = 'The password has been used.'; |
||
138 | |||
139 | public static $eventPasswordUsed = 'passwordUsed'; |
||
140 | |||
141 | /** |
||
142 | * This method is only used for password hash attribute validation. |
||
143 | * If password is used, the `eventPasswordUsed` event will be triggered. |
||
144 | * |
||
145 | * @param string $attribute |
||
146 | * @param mixed $params |
||
147 | * @param type $validator |
||
148 | */ |
||
149 | 1 | public function checkPasswordNotUsed($attribute, $params, $validator) |
|
158 | } |
||
159 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: