Genesis2001

CodeIgniter authenticate_user Accounts System

Jan 6th, 2012
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1. function authenticate_user( $username, $password )
  2. {
  3.     $CI = &get_instance();
  4.     $accounts_table = $CI->config->item('accounts_table');
  5.    
  6.     $salt = $CI->db->select('salt')->from($accounts_table)->where('username', $username)->limit(1)->get()->result->row(0)->salt;
  7.    
  8.     if ( !$salt OR empty($salt) )
  9.     {
  10.         return false;
  11.     }
  12.    
  13.     $password = apply_salt($password, $salt);
  14.    
  15.     $where = array(
  16.             'username' => $username,
  17.             'password' => $password
  18.         );
  19.    
  20.     $results = $CI->db->get_where( $accounts_table, $where, 1 );
  21.    
  22.     if ( $results )
  23.     {
  24.         $user = $results->row(0);
  25.        
  26.         if ( $user->lockout_time != 0 )
  27.         {
  28.             $lockout_expire = $CI->config->item('login_lockout_expire');
  29.            
  30.             if ( time() - strtotime($user->lockout_time) >= $lockout_expire )
  31.             {
  32.                 return array( 'user_id' => $user->user_id, 'activated' => $user->activated, 'locked' => !unlock_account($user->user_id) );
  33.             }
  34.             else
  35.             {
  36.                 return array( 'user_id' => $user->user_id, 'locked', 'locked' => true );
  37.             }
  38.         }
  39.        
  40.         if ( $user->activated != 1 )
  41.         {
  42.             return array( 'user_id' => $user->user_id, 'activated' => $user->activated );
  43.         }
  44.        
  45.         return $user->user_id;
  46.     }
  47.    
  48.     return false;
  49. }
Add Comment
Please, Sign In to add comment