开发者

cakephp:registration page password displays hash value with password symbols (dots) when register button clicked

I'm trying to create a user registration page based on cakephp cookbook.

When I click the register button, the password displays the hashed value with password symbol (ie. 40 dots) and since, i'm having validation in my user model, the error message displays (maximum 8 characters long). The page is not being redirected to the home page.

I even tried removing the password validation, but the hashed value is still getting displayed ie. 40 dots.

Can someone tell me on how I can keep the password as it is without displaying the hashed values and redirect it to the home page when password and confirm password matches? Thank you.

The following is my code:

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');
   ?>


echo $this->Form->input('password',array('value'=>''));
echo $this->Form->input('password2',array('value'=>'','label'=>'confirm password','type'=>'password'));

The user needs to type the password again. That's how most websites do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜