Skip to content

Instantly share code, notes, and snippets.

@randika
Created January 30, 2014 07:15
Show Gist options
  • Save randika/8704002 to your computer and use it in GitHub Desktop.
Save randika/8704002 to your computer and use it in GitHub Desktop.
<?php
$user_signup_password = 'password';
$pass = urlencode($user_signup_password);
$salt = substr(str_replace('+', '.', base64_encode(sha1(microtime(true), true))), 0, 22);
// 2a is the bcrypt algorithm selector
// 12 is the workload factor
$pass_crypt = crypt($pass, '$2a$12$'. $salt);
echo "signup password: ".$pass_crypt; // You save this on database
$user_login_password = "password"; // This is what the user will entering when login - change this to see if it works
echo "<br>";
// USER AUTH CHECK - compare $user_login_password with $pass_crypt stored in database
if ($pass_crypt == crypt($user_login_password, $pass_crypt)) {
echo "Success! Valid password";
} else {
echo "Invalid password";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment