Я пытаюсь создать страницу регистрации пользователя на основе кулинарной книги cakephp.
Когда я нажимаю кнопку регистрации, пароль отображает хэшированное значение с символом пароля (т. Е. 40 точек), и, поскольку у меня есть проверка в моей пользовательской модели, отображается сообщение об ошибке (максимум 8 символов)).Страница не перенаправляется на домашнюю страницу.
Я даже пытался удалить проверку пароля, но хеш-значение все еще отображается, т.е.40 точек.
Может кто-нибудь сказать мне, как я могу сохранить пароль, как он есть, без отображения хэшированных значений и перенаправить его на домашнюю страницу, когда пароль и подтверждение пароля совпадают?Спасибо.
Вот мой код:
user.php
<?php
class User extends AppModel{
var $name='User';
var $validate=array(
'username'=>array(
'userRule1'=>array(
'rule'=>'alphaNumeric',
'required'=>true,
'allowEmpty'=>false,
'message'=>'Alphabets and numbers only'
),
'userRule2'=>array(
'rule'=>array('between',5,15),
'message'=>'Between 5 to 15 characters'
)
),
'password'=>array(
'rule'=>'notEmpty',
'required'=>true,
'allowEmpty'=>false,
'message'=>'Password required!'
),
'password2'=>array(
'rule'=>array('maxLength',8),
'required'=>true,
'allowEmpty'=>false,
'message'=>'Maximum 8 characters long'
)
);
}
?>
users_controller.php
<?php
class UsersController extends AppController{
var $name='Users';
var $components=array('Auth','Session');
var $helpers=array('Form','Html');
function beforeFilter(){
$this->Auth->allow('register');
}
function index(){
}
function login(){
}
function logout(){
$this->redirect($this->Auth->logout());
}
function register(){
if (!empty($this->data)){
//$this->Auth->password($this->data['User']['password2']) used to get what the hashed password would look like
if ($this->data['User']['password']==$this->Auth->password($this->data['User']['password2'])){
if ($this->User->save($this->data)){
//send signup email containing password to the user
$this->Auth->login($this->data); //automatically logs a user in after registration
$this->redirect('/pages/home');
}//end if ($this->User->save($this->data))
}//end if ($this->data['User']['password']
else{
//$this->flash('Typed passwords did not match','users/register',5);
$this->Session->setFlash('Typed passwords did not match');
}
}//if (!empty($this->data))
}//end function register
}//end class
?>
/ users / register view
<?php
echo $this->Form->create('User',array('action'=>'register'));
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->input('password2',array('label'=>'confirm password','type'=>'password'));
echo $this->Form->end('Register');
?>