I'm trying ot make a Sha512 encryption for the passwords in Yii, but it isn;t working
i beleive the code is this $model->PassWord=crypt($model->PassWord,'salt');
But i am getting this as an error Fatal error: Call to undefined function CRYPT_SHA512() in protected/controllers/UsersController.php on line 73
Any ideas?
Full code:
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'];
$model->PassWord=crypt_SHA512($model->PassWord,'salt');
if($model->save())
$this->redirect(array('view','id'=>$model->users_id));
}
$this->render('create',array(
'model'=>$model,
));
}
edit
This $model->PassWord=crypt($model->PassWord,'$6$rounds=1212$16charactersaltt');
makes the password encrypted, Great!
Now when trying to login i get this error
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /web/users/m2052626/AST_14/Bugg.ly2/protected/components/UserIdentity.php on line 25
This is my code originally for the login
public function authenticate()
{
$user=Users::model()->findByAttributes(array('email'=>$this->username));
if($user===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
//else if($record->PassWord!==md5($this->password))
else if($user->PassWord!==($this->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$user->users_id;
// $this->setState('title', $record->title);
$this->errorCode=self::ERROR_NONE;
And i have tried to replace this else if($user->PassWord!==($this->password))
with this if (crypt($this->password '$6$rounds=1212$16charactersaltt') == $user->PassWord) { echo "password matched"; } else { echo "password did not match"; }
which didnt work