Laravel Classroom image

To post your Question Join Classroom
Lesson Topics's No:-  |1 | 2|Last

Sometimes you need to protect your important data. Laravel provides two different methods to
help you do that. One-way and two-way encryption. Let’s take a look at these methods.
21.1 One Way Encryption
One way encryption is the best way to store user passwords, or other sensitive data. One way
means that your data can be converted into an encrypted string, but due to a complex algorithm
with painful maths, reversing the process is not possible.
This makes storing passwords a doddle! Your customers don’t have to worry about you knowing
their passwords, but you are still able to compare them (by hashing the password they provide)
or change the password if needed.
Note that hashing is the process of creating a hash or encrypted string from another
Let’s take a look at how password hashing works with one way encryption.
1 <?php
3 $pass = Input::get('password');
Now we have retrieved the password from our ‘create user’ form, but it’s in plain-text! Let’s
hash it quickly so we can store it securely in our database.
1 <?php
3 $pass = Hash::make($pass);
We have used another of Laravel’s highly expressive methods, this time make()ing a new Hash.
Our $pass value will now contain a bcrypt encrypted version of our password, neat!
Let’s say that our user has entered their password to login, and now we need to check to see if
its authentic before they can be logged into the system. We can simply compare our hash to the
value stored in the database with the check() method.
1 <?php
3 $pass = Input::get('password');
4 if ( Hash::check($pass, $user->password) )
5 {
6 // auth successful
7 }The check() method accepts two parameters, the plain-text value provided by your user, and
the hashed password that you have stored. It returns a boolean value to indicate whether the
true values match or not.
What if we want to decode our data at a later date? Let’s two way encrypt it.



Skills    Laravel

Qualifications :-
Location :-,,,

  Students (0)