Created
November 18, 2012 12:23
-
-
Save krhitoshi/4104946 to your computer and use it in GitHub Desktop.
PHP script to create bcrypt hash password
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
#!/usr/bin/php | |
<?php | |
function create_salt(){ | |
$salt_source = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
$num = strlen($salt_source)-1; | |
$salt = ""; | |
for($i=0; $i<22; $i++){ | |
$index = mt_rand(0, $num); | |
$salt .= $salt_source[$index]; | |
} | |
return $salt; | |
} | |
if ( count($argv) != 2 ){ | |
$script = basename(__FILE__); | |
echo "Usage: $script password\n"; | |
exit; | |
} | |
$password = $argv[1]; | |
$salt = create_salt(); | |
$hash = crypt($password, '$2a$10$'.$salt); | |
print $hash . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment