Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php yii中md5两次加密的密码_Php_Yii - Fatal编程技术网

Php yii中md5两次加密的密码

Php yii中md5两次加密的密码,php,yii,Php,Yii,我一直在用Yii框架开发一个应用程序。我创建了一个注册表,其中有一个字段是密码。注册后,我看到数据库中存储的密码结果被加密了两次md5 我在模型中写道: protected function afterValidate() { $this->password = $this->encrypt($this->password); } public function encrypt($value) { return md5($value); } 内置控制器 pub

我一直在用Yii框架开发一个应用程序。我创建了一个注册表,其中有一个字段是密码。注册后,我看到数据库中存储的密码结果被加密了两次md5

我在模型中写道:

protected function afterValidate()
{
    $this->password = $this->encrypt($this->password);
}
public function encrypt($value)
{
    return md5($value);
}
内置控制器

public function actionRegistration()
{
    $model=new User('registration');

    // Uncomment the following line if AJAX validation is needed
   $this->performAjaxValidation($model);

    $model->scenario = 'registerwcaptcha';
    if(isset($_POST['User']) )
    {
        $model->attributes=$_POST['User'];
        $keystring = md5( rand(0,1000) ); // Generate random 32 character hash and assign it to a local variable.
        $model->keystring = $keystring;
        //$model->password = md5( $model->password );
        if($model->validate())
        {
            // and here is the actual HACKY part
            $model->scenario = NULL;

            // save user registration
            if($model->save())                                       
                $this->redirect(array('emailverify'));
        }

    }

    $this->render('registration',array(
        'model'=>$model,
    ));
}

有人能帮我吗。

最新版本的Yii内置了密码哈希功能

要进行散列,可以使用:

$hash=CPasswordHelper::hashPassword($password)

并核实:

if (CPasswordHelper::verifyPassword($password, $hash)){
    // password matches with hash
}
else{
    // password doesn't match with hash
}
有关更多详细信息,请参阅本页:


您是如何知道密码加密两次的?1)MD5不是“加密”。2) 所以。。。更改代码,使其不散列两次。。。?通过验证函数对数据进行隐式更改是一个糟糕的想法。显式散列密码一次,而不是隐式散列密码两次。我有一个测试密码,我用md5插入表中,然后用md5再次更新该字符串,结果与通过注册保存的内容匹配。顺便说一句,md5完全不适合用于密码保护。它几乎比没用更糟糕,因为它让你相信你是安全的,而实际上你的密码可以在几秒钟内被强制使用。使用bcrypt/。