I'm attending CakeFest 2010!

5.2.3 Troubleshooting Auth Problems

It can sometimes be quite difficult to diagnose problems when it's not behaving as expected, so here are a few pointers to remember.

Password hashing

When posting information to an action via a form, the Auth component automatically hashes the contents of your password input field if you also have data in the username field. So, if you are trying to create some sort of registration page, make sure to have the user fill out a 'confirm password' field so that you can compare the two. Here's some sample code:

<?php 
function register() {
    if ($this->data) {
        if ($this->data['User']['password'] == $this->Auth->password($this->data['User']['password_confirm'])) {
            $this->User->create();
            $this->User->save($this->data);
        }
    }
}
?>
  1. <?php
  2. function register() {
  3. if ($this->data) {
  4. if ($this->data['User']['password'] == $this->Auth->password($this->data['User']['password_confirm'])) {
  5. $this->User->create();
  6. $this->User->save($this->data);
  7. }
  8. }
  9. }
  10. ?>