Advertisement
Guest User

Untitled

a guest
Jul 6th, 2010
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. <?php
  2.  
  3.     function createpasswordhash($user, $raw_pass)
  4.     {
  5.         // this should ONLY be used to create NEW passwords, as
  6.         // the salt is based on the time
  7.         $salt = sha1($user . array_sum(explode(' ', microtime())));
  8.         $raw = $salt . sha1(sha1($user) . sha1($salt . $raw_pass));
  9.        
  10.         return $raw;
  11.     }
  12.    
  13.     function checkpassword($user, $pass, $hash)
  14.     {
  15.         $salt = substr($hash, 0, 40);
  16.         $check = $salt . sha1(sha1($user) . sha1($salt . $pass));
  17.        
  18.         if($check == $hash) return true;
  19.        
  20.         return false;
  21.     }
  22.    
  23.     function checkLogin($user, $rawpass)
  24.     {
  25.         $user = mysql_real_escape_string($user);
  26.         if(isUserBanned($user)) return 'User is banned.';
  27.        
  28.         global $DB;
  29.         $query = $DB->Query("SELECT `password`, `active`, `enabled` FROM `users` WHERE `username` = '{$user}' LIMIT 1", __FILE__, __LINE);
  30.        
  31.         if(!$query) return 'Username or password not found.';
  32.         $row = $DB->Fetch($query);
  33.         if(checkpassword($user, $rawpass, $row['password']))
  34.         {
  35.             if($row['active'] == 0) return 'This account is not yet activated.';
  36.             if($row['enabled'] == 0) return 'This account has been disabled.';
  37.            
  38.             return '';
  39.         }
  40.        
  41.         return 'Invalid username/password combination.';
  42.     }
  43.    
  44.     function validpassword($user, $pass)
  45.     {
  46.         // i dont really use this...basically, it checks for some normal characters
  47.         // and also that the username isnt in the password, or too similar
  48.         $pa = 0;
  49.        
  50.         $matches = array();
  51.         preg_match('/[^a-zA-Z0-9_\.]/', $user, $matches);
  52.        
  53.         if(isset($matches[0]))          return 1;
  54.        
  55.         if(strlen($pass) < 6)               return 2;
  56.         if(strpos($pass, $user))            return 3;
  57.        
  58.         similar_text($user, $pass, $pa);
  59.         if($pa >= 40)                       return 4;
  60.        
  61.         return 0;
  62.     }
  63.    
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement