How to – password hashing in cakephp

November 25, 2007 at 6:44 am | Posted in cakephp | 9 Comments
Tags: , ,

How do you do password hashing in cakephp ?

The answer is really simple, use the Security class provided by cakephp.

Example usage –

In your controller, do the following
$this->data['User']['password'] = Security::hash($this->data['User']['password']);

where ‘User’ is the model and ‘password’ is the attribute that is used to capture the password entered by the user.

By default, Security::hash takes the type sha1.

And if you want to validate or check the password entered by the user against the hashed password stored in db, use the hash method and perform the check.

9 Comments »

RSS feed for comments on this post. TrackBack URI

  1. Thank’s dude!

  2. Don’t forget that the Auth component will automatically hash passwords.

    Security::hash($password, ‘sha256’, true);
    This would produce a more secure result.

  3. Thanks dude, I will give it a try and check if it works. But it sound logic!

  4. thanks dude

  5. Thanks, good tip!

  6. Thanks…

  7. i propose using a behavior for this:
    http://www.dereuromark.de/2011/08/25/working-with-passwords-in-cakephp/
    this way you have a unique handle for user and admin area as well as “forgotten password” feature etc

  8. Thanks a lot …^^

  9. nice logic


Leave a comment

Blog at WordPress.com.
Entries and comments feeds.