1
votes

I managed to get authentication to work by following the tutorial from this page http://planetcakephp.org/aggregator/items/2604-create-simple-user-authentication-using-cakephp%E2%80%99s-auth-component

How do I make sure when I'm in the register page, and the password and confirm password the user supplied doesn't match, the password field will be repopulated with the value the user enter and not the hashed version of it?

Thanks,
Tee

2
Why would you want to in the first place? The password is wrong. Password fields are masked, you can't see what's in there. What's the use of repopulating it? The user would have to type from the beginning anyway. - deceze
infact both the password fields should be reset if some goes wrong with the form submission. Isn't it ? - Gaurav Sharma

2 Answers

1
votes

Instead of using trickpassword, you already have the password_confirm field with the unhashed password. You can use rules similar to these to check the password field against blank passwords... And then hash the password_confirm to make sure the two are the same.

http://bin.cakephp.org/saved/42156

0
votes

I don't think it's necessary to figure this out because of the feature of password input.Also it would be difficult to do this since you've used the Auth component.From the cookbook:

The auth component will automatically hash the password field if the username field is also present in the submitted data

That means you will lost the original password data after your submit it.However,I think there's a tricky way to approach that with javascript:adding a hidden type input in the register view file which is the same value but different name with $form->input('password');,then you can retrieve it in the action to display in the password input text.e.g

if ($this->data['User']['password'] == $this->Auth->password($this->data['User']['password_confirm'])) 
{
    $this->User->save($this->data);
    $this->Session->setFlash("your data has been saved.");
    $this->redirect("index");
}
else
{
    $this->data['User']['password'] = $this->data['User']['trickpassword'];
    /*i prefer this
    $this->data['User']['password'] = '';
    $this->data['User']['password_confirm'] = '';
    */
    $this->Session->setFlash('Password confirm fail!');
}