2014-09-26 59 views
-1

我想在将密码插入数据库之前更改要加密的密码,但它不起作用。它说密码很长。用Yii加密的密码问题

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, 
    )); 
} 
+0

增加tabel中的密码字段的大小以及用户模型中的规则的大小也会增加该大小,以使您的模型验证结果为true。 – 2014-09-26 10:45:09

+0

您在模型类规则中使用的密码长度是多少? – Athipatla 2014-09-26 11:14:28

+0

你的回答是正确的milz谢谢男人:) – 2014-09-26 11:36:19

回答

1

你使用什么数据库和数据类型..? 如果使用mysql,则可以使用char(32)或varchar(32)导致MD5加密出来的长度为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 
    ); 
} 

可能是消息“的密码是长”出现,因为你的规则()验证。

+0

问题是密码的最大大小 – 2014-09-26 11:35:23