Skip to content

Instantly share code, notes, and snippets.

@alpenzoo
Created September 27, 2017 08:52
Show Gist options
  • Save alpenzoo/7e2021f381fc3bb03f42fa3d89f7f4f5 to your computer and use it in GitHub Desktop.
Save alpenzoo/7e2021f381fc3bb03f42fa3d89f7f4f5 to your computer and use it in GitHub Desktop.
<?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.';
}
?>
@alpenzoo
Copy link
Author

First method offers sha-512 hash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment