Share the password processing method on the php login page. In the controller: elseif (! $ Model-validatePassword ($ data-password :? PhpclassXBaseModelextendsCActiveRecord {*** check user password *** @ returnboo controller: elseif (! $ Model-> validatePassword ($ data-> password ))
The code is as follows:
Class XBaseModel extends CActiveRecord
{
/**
* User password detection
*
* @ Return boolean
*/
Public function validatePassword ($ password)
{
Return $ this-> hashPassword ($ this-> password) ===$ password;
}
/**
* Encrypt the password
* @ Return string password
*/
Public function hashPassword ($ password)
{
Return md5 ($ password );
}
}
Or:
If ($ user & $ user-> password ==$ user-> hashPassword ($ this-> password, $ user-> salt )){
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 = '1234567890abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz ';
$ Len = strlen ($ str)-1;
$ String = '';
For ($ I = 0; $ I <6; $ I ++ ){
$ String. = $ str [mt_rand (0, $ len)];
}
Return $ string;
}
Or:
The code is as follows:
Public function validatePassword ($ password ){
Return $ this-> hashPassword ($ password, $ this-> salt) ===$ this-> password;
}
Public function hashPassword ($ password, $ salt)
{
Return md5 ($ salt. $ password );
}
Protected function generateSalt ()
{
Return uniqid ('', true );
}
Note: If salt exists, the database field must have salt ..
Success (! $ Model-validatePassword ($ data-password) code is as follows :? Php class XBaseModel extends CActiveRecord {/*** check user password ** @ return boo...