In the controller: elseif(!$model->validatePassword($data->password))
Copy code The code is as follows:
class XBaseModel extends CActiveRecord
{
/**
* Detect user password
* *
* @return boolean
*/
public function validatePassword ($password)
{
return $this->hashPassword($this->password) = == $password;
}
/**
* Password is encrypted
* @return string password
*/
public function hashPassword ($password)
{
return md5($password);
}
}
or:
if ($user && $user->password == $user->hashPassword($this->password, $user->salt)) {
Copy code The code is as follows:
public function validatePassword($password) {
return $this->hashPassword ($password, $this->salt) === $this->password;
}
public function hashPassword($password, $salt) {
return md5(md5( $ password). $ SALT);
}
Public function generatesalt () {
$ Str = ' Rstuvwxyz ';
$ Len = Strlen ($ Str) -1;
$string = '';
for ($i = 0; $i < 6; $i++) {
$string .= $str[mt_rand(0, $len)];
}
return $string;
}
or:
Copy code The code is as follows:
public function validatePassword($password) {
return $this- >hashPassword($password,$this->salt)===$this->password;
}
public function hashPassword($password,$salt)
{
, . > }
Note: If there is salt, the fields in the database must have salt. .
http://www.bkjia.com/PHPjc/824853.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/824853.htmlTechArticleIn the controller: elseif(!$model-validatePassword($data-password)) Copy the code as follows: ? php class XBaseModel extends CActiveRecord { /** * Detect user password* * @return boo...