How to create hashed password in Laravel 4.2

You need to do encryption when you want to store/save password on your application, in laravel 4.2 you can use the hashing technique to save and also checking the password, in this article i will show you how to do that.

You can use the hash class to create a hashed password, here's an example creating hashed password:
The code above is calling the 'Hash' class and runs the static method called 'make', in reality you might want to put it on a variable, like this:
$pass = $Hash::make('thepassword');
And then you can store the password to the database without worrying someone can read the password.

The now you need to know how to check the hashed password correct or not, to check the hashed password you can call the static method 'check', like this.
Hash::check($plain_text, $hashed_text);
The static method 'check' takes two input parameters, the first one is the plain text that going to be checked, this could be input password from the user when they try to login, and the second parameter is the hashed password/string, probably coming from the database.

If the plain text on the left is match with the hashed text on the right then it will return true, otherwise it will return false, here's an example:

$pass = Hash::make('test123');

if (Hash::check('test', $pass)) {

echo 'password correct';

} else {

echo 'password wrong';

What do think the output will be? please leave in the comment below.

No comments :

Post a Comment

Leave A Comment...