Php Yii的加密密码问题

Php Yii的加密密码问题,php,yii,Php,Yii,我想在将密码插入数据库之前更改密码以进行加密,但它不起作用。 上面说密码太长了 public function actionCreate() { $model = new Users; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Users'])) {

我想在将密码插入数据库之前更改密码以进行加密,但它不起作用。 上面说密码太长了

    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'];
        $password = $_POST['Users']['password'];
        $model->password = md5($password);
        if ($model->save())
            $this->redirect(array('view', 'id' => $model->id));
    }

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

您使用的数据库和数据类型是什么。。? 如果使用mysql,则可以使用char(32)或varchar(32),因为MD5 encrypted的长度为32个字符

注意你的模型规则

public function rules() {
   return array (
     array('password', 'length', 'max'=>20), 
     //length means your strings password that you entered can not more than 20 character
     //but its not effect with password encrypted result
   ); 
}

可能是因为您的规则()而出现“密码太长”的消息验证器。

增加用户模型中选项卡和规则中密码字段的大小增加该大小,以便模型验证结果为真。模型类规则中使用的密码长度是多少?答案是正确的milz感谢男士:)我反对使用md5进行密码加密,它不再被认为是安全的,即使是它的创建者()。改为查找Yii的密码帮助函数。问题是密码的最大大小