0
我正在尝试基于cakephp食谱创建一个用户注册页面。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
?>
/用户/注册视图
<?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');
?>
是的,我的权利,它现在工作正常后,添加'价值'=>''。 – vaanipala
,但密码的maxLength 8字符验证规则不起作用。当我输入6个字符时,我仍然收到错误消息“最多8个字符长”。 – vaanipala
好的,现在我已经修改了用户模型中的验证,并且everthing正常工作。我只指定了'notEmpty'作为密码的规则,而没有其他规定。如果我有任何其他密码验证,我不工作。非常感谢你的指导。 – vaanipala