daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Aug 30th, 2013 210 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. demo = $2y$10$Zjk5YzQ4ZTlhMzNlNTUzMO3Wnm1FqXmAb6/4DmyptNGoEdWGLwls.
  2.        
  3. function password_encrypt($password) {
  4.   $hash_format = "$2y$10$";   // Tells PHP to use Blowfish with a "cost" of 10
  5.   $salt_length = 22;                    // Blowfish salts should be 22-characters or more
  6.   $salt = generate_salt($salt_length);
  7.   $format_and_salt = $hash_format . $salt;
  8.   $hash = crypt($password, $format_and_salt);
  9.     return $hash;
  10. }
  11.  
  12. function generate_salt($length) {
  13.   // Not 100% unique, not 100% random, but good enough for a salt
  14.   // MD5 returns 32 characters
  15.   $unique_random_string = md5(uniqid(mt_rand(), true));
  16.     // Valid characters for a salt are [a-zA-Z0-9./]
  17.   $base64_string = base64_encode($unique_random_string);
  18.     // But not '+' which is valid in base64 encoding
  19.   $modified_base64_string = str_replace('+', '.', $base64_string);
  20.     // Truncate string to the correct length
  21.   $salt = substr($modified_base64_string, 0, $length);
  22.     return $salt;
  23. }
  24.  
  25. function password_check($password, $existing_hash) {
  26.     // existing hash contains format and salt at start
  27.   $hash = crypt($password, $existing_hash);
  28.   if ($hash === $existing_hash) {
  29.     return true;
  30.   } else {
  31.     return false;
  32.   }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top