Created
September 27, 2017 08:52
-
-
Save alpenzoo/7e2021f381fc3bb03f42fa3d89f7f4f5 to your computer and use it in GitHub Desktop.
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
<?php | |
//create random hash, please notice $6$ as first chars in salt string | |
$salt = "$6$5e2de398074f9213"; | |
$hash = crypt('pswt1', $salt); | |
echo $hash; | |
//mariaDB compatible code: select ENCRYPT('pswt1', CONCAT('$6$', SUBSTRING(SHA(RAND()), -16))); | |
echo "<hr>"; | |
if (password_verify('pswt1', $hash)) { | |
echo 'Password is valid!'; | |
} else { | |
echo 'Invalid password.'; | |
} | |
echo "<hr>"; | |
//second method, not recommended | |
$storedHash = password_hash(hash('sha512', "gigi", true), PASSWORD_DEFAULT); | |
echo $storedHash; | |
if (password_verify(hash('sha512', "gigi", true), $storedHash)) { | |
echo 'Password is valid!'; | |
} else { | |
echo 'Invalid password.'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First method offers sha-512 hash.