Archive

Archive for June, 2010

Password hashing class (phpass) converted to CodeIgniter library

June 4th, 2010 6 comments

Password hashing class phpass was suggested in /r/php/ so I decided to use it on one of my CodeIgniter applications. I changed a bit how constructor works to be able to load it as any other CodeIgniter library and modified it’s methods to be able to call them statically.

If you want to give it a try – download it and copy Hash.php to your /application/libraries directory.

 
In your controller, load the library:

1
$this->load->library('hash');

 
Now you can use static methods anywhere in your application – your auth library, users controller, etc.

 
For example, to hash a password you can do this:

1
$hash = Hash::HashPassword($this->input->post('password'));

 
To verify password:

1
2
3
4
if (Hash::CheckPassword($this->input->post('password'), $hash) !== TRUE)
{
	// Login failed
}

 
Hope you’ll find it useful.

Tags: