Home >Backend Development >PHP Tutorial >Sharing the password processing method for PHP login page_PHP tutorial

Sharing the password processing method for PHP login page_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:25:58816browse

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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn