Last active
August 3, 2017 05:04
-
-
Save Mauryashubham/ab4c9e3ce768c2dce131516fd58ffb28 to your computer and use it in GitHub Desktop.
Password Hashing and Crypting Using PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hi all , Welcome to shubhammaurya.com , Today we are going to discuss , | |
how to Hash Password and Crypt Password Using PHP. | |
We are going to use 2 Methods. | |
1.crypt() and 2.password_hash() | |
1.Make a file in notepad and save it as index.php and paste the below code. | |
<?php | |
echo “<br><br>Password crypt()<br>”; | |
//Password crypt() | |
$pass=”password”; //You can take input from user also | |
$pass_check=”password”; | |
$hashed_password = crypt($pass,'st'); // let the salt be automatically generated | |
echo “Hashed Password : “.$hashed_password; | |
if (hash_equals($hashed_password, crypt($pass_check, $hashed_password))) | |
{ | |
echo “<br>Password verified!”; | |
} | |
echo “<br><br>Password Hashing<br>”; | |
//Password Hashing$options = [‘cost’ => 12]; | |
$new_password = password_hash($pass, PASSWORD_DEFAULT, $options); | |
echo “<br>New Password : “.$new_password; | |
if(password_verify($pass,$new_password)) | |
{ | |
echo “<br>Password verified!”; | |
} | |
else | |
{ | |
echo “<br>Password Not verified!”; | |
} | |
?> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Output : | |
Password crypt() | |
Hashed Password : $1$9J1.cg1.$Jn4Wqanhwrb1ftqvJPH4e0 | |
Password verified! | |
Password Hashing | |
New Password : $2y$12$GawqdMGynl9DbjEXmxNkLuL.Bwq6OIgd3zrIDBDd.71QgYEKbGX9G | |
Password verified! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment