Created
May 18, 2014 10:09
-
-
Save lesander/c1a4f19eeaf32a66ed53 to your computer and use it in GitHub Desktop.
Hash password securely with sha512, salt and a secret key
This file contains 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 | |
// Hash file using sha512, salt and a secret key. | |
// By github.com/lesander | |
// DON'T FORGET TO EDIT YOUR $secretkey !!! | |
// - Hashing your Password - | |
// Example 1 Request: | |
// http://domain.com/hash.php?s=myPassword | |
// Example 1 Result: | |
// { | |
// ["salt"]="76d8e4fcbab6e1947cd2c97dcaec1f9d9416147351698a118b22e85029307655e44ffdd4a17a203b76b8e65d90fbe51f842c46559601310230125d24369c26c6", | |
// ["hash"]="0b40fab1223bdda2d955dfcbb0eb35159c3a53f4cee1de5d78071125c0b997847870ad1869a825599c556c64a8f7baedb6287c2f6c37def5989ed84a2f82b409" | |
// } | |
// - Checking your Password - | |
// Example 2 Request: | |
// http://domain.com/hash.php?s=givenPassword&n=76d8e4fcbab6e1947cd2c97dcaec1f9d9416147351698a118b22e85029307655e44ffdd4a17a203b76b8e65d90fbe51f842c46559601310230125d24369c26c6 | |
// Example 2 Result: | |
// { | |
// ["salt"]="76d8e4fcbab6e1947cd2c97dcaec1f9d9416147351698a118b22e85029307655e44ffdd4a17a203b76b8e65d90fbe51f842c46559601310230125d24369c26c6", | |
// ["hash"]="0b40fab1223bdda2d955dfcbb0eb35159c3a53f4cee1de5d78071125c0b997847870ad1869a825599c556c64a8f7baedb6287c2f6c37def5989ed84a2f82b409" | |
// } | |
$string = $_GET['s']; | |
if(empty($string)){ | |
die(""); | |
} | |
$secretkey = "ENTER_SOME_RANDOM_STUFF_HERE"; | |
if(empty($_GET['n'])){ | |
$salt = hash('sha512', microtime(true).mt_rand(10000,90000)); | |
} | |
else{ | |
$salt = $_GET['n']; | |
} | |
$hash = hash('sha512', $salt.$string.$secretkey); | |
echo('{ ["salt"]="'.$salt.'", ["hash"]="'.$hash.'" }'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment