Php Yii从Sha登录
当用户注册时,我对密码进行了以下加密:Php Yii从Sha登录,php,yii,hash,sha512,Php,Yii,Hash,Sha512,当用户注册时,我对密码进行了以下加密: public function actionCreate() { $model=new Users; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if(isset($_POST['Users'])) { $model->attributes=$_POST[
public function actionCreate()
{
$model=new Users;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Users']))
{
$model->attributes=$_POST['Users'];
// how many times the string will be hashed
$rounds = 10000;
// @todo Use real salt here.
$salt = 'salt';
// pass in the password, the number of rounds, and the salt
// $5$ specifies SHA256-CRYPT, use $6$ if you really want SHA512
$model->PassWord=crypt($model->PassWord, sprintf('$6$rounds=%d$%s$', $rounds, $salt));
if($model->save())
$this->redirect(array('view','id'=>$model->users_id));
}
$this->render('create',array(
'model'=>$model,
));
}
现在我知道我需要更改代码来验证用户,代码如下:
else if($user->PassWord!==$this->password)
如果我使用crypt
方法,我通常会使用以下方法:
else if($user->PassWord!==crypt($this->password,'salt'))
如何更改登录脚本以使用
sha512
?您应该使用与创建
中的密码哈希相同的参数:
$rounds = 10000;
$salt = 'salt';
if($user->PassWord !== crypt($this->password, sprintf('$6$rounds=%d$%s$', $rounds, $salt)))
那么你真正的问题是什么?显示的代码似乎与您的标题或描述不匹配。就标题而言,您不能“取消加密”SHA-512,因为它没有加密,它是一个哈希,因此是单向的。可能重复或可能:对不起,完全误解了实际问题,这是密码登录。我认为这将是我使用sha512加密和salt的方法。(which确实如此)我只需要在登录时匹配密码。根据您的PHP版本,我建议使用PHP的内置密码API。