# Error with logging in cakephp 2.x

**URL:** <https://discourse.cakephp.org/t/error-with-logging-in-cakephp-2-x/7817>\
**Category:** Need Help\
**Created:** [May 14, 2020, 3:38pm UTC](https://discourse.cakephp.org/t/error-with-logging-in-cakephp-2-x/7817 "2020-05-14T15:38:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ar999](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Ar999](https://discourse.cakephp.org/u/Ar999)\
**Post date:** [May 14, 2020, 3:38pm UTC](https://discourse.cakephp.org/t/error-with-logging-in-cakephp-2-x/7817/1 "2020-05-14T15:38:25Z")

</div>

I’m having trouble with authentication for logging in. Whenever I try to login an existing user it flashes my error code.

// App Controller code

 ![AppController](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/0/0388031c790f579ae880b45ae82c9e32d3cc8559.png)

// User Model code

 ![Screenshot from 2020-05-14 08-33-13](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/9/979b371e819772b35d434cbca94cd1cc194a4442.png)

// User Controller code

 ![Screenshot from 2020-05-14 08-33-18](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/5/56bb1e7b919c7980a50fde89f7323d9148039642.png)

---

<div class="post-metadata">

**Author:** ![Foggies](https://avatars.discourse-cdn.com/v4/letter/f/a183cd/32.png) [@Foggies](https://discourse.cakephp.org/u/Foggies)\
**Post date:** [May 15, 2020, 12:10am UTC](https://discourse.cakephp.org/t/error-with-logging-in-cakephp-2-x/7817/2 "2020-05-15T00:10:05Z")

</div>

This might be caused by the password is not hashed properly. In your user model, you just validate the input. You should hash the password using the following code.

```auto
<?php
App::uses('AppModel', 'Model');
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');

class User extends AppModel {

public function beforeSave($options = array()) {
    if (isset($this->data[$this->alias]['password'])) {
        $passwordHasher = new BlowfishPasswordHasher();
        $this->data[$this->alias]['password'] = $passwordHasher->hash(
            $this->data[$this->alias]['password']
        );
    }
    return true;
}
```

---

<div class="post-metadata">

**Author:** ![Ar999](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Ar999](https://discourse.cakephp.org/u/Ar999)\
**Post date:** [May 15, 2020, 2:44pm UTC](https://discourse.cakephp.org/t/error-with-logging-in-cakephp-2-x/7817/3 "2020-05-15T14:44:20Z")

</div>

I implemented password hashing, but it’s still not allowing me to login.
