Skip to content

Instantly share code, notes, and snippets.

@krhitoshi
Created November 18, 2012 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krhitoshi/4104946 to your computer and use it in GitHub Desktop.
Save krhitoshi/4104946 to your computer and use it in GitHub Desktop.
PHP script to create bcrypt hash password
#!/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