Guest User

Untitled

a guest
May 8th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.70 KB | None | 0 0
  1. <?php
  2.  
  3.         class login
  4.         {  
  5.    
  6.                 private function initQuery($user)
  7.                 {  
  8.    
  9.                         $query = "SELECT userName, passWord, created FROM users WHERE userName = '$user'";
  10.                         $result = mysql_query($query);
  11.                         $check = mysql_num_rows($result);
  12.  
  13.                         if($check == 1)
  14.                         {  
  15.  
  16.                                 $row = mysql_fetch_assoc($result);
  17.                                 return $row;
  18.  
  19.                         } else {
  20.    
  21.                                 $_SESSION['login']['error']['user'] = "Invalid username or password";
  22.                                 return false;
  23.                                 exit;
  24.  
  25.                         }  
  26.  
  27.                 }  
  28.  
  29.                 public function loginForm()
  30.                 {  
  31.                         $form = "<table class="loginForm">\n";
  32.                                 .= "<form method=\"post\">\n";
  33.                                 .= "<tr><td><input type=\"text\" name=\"userName\" placeholder=\"Username\" /></td></tr>\n";
  34.                                 .= "<tr><td><input type=\"password\" name=\"passWord\" placeholder=\"Password\" /></td></tr>\n";
  35.                                 .= "</form>\n";
  36.                                 .= "</table>\n";
  37.                         print $form;
  38.                 }  
  39.  
  40.                 public function validateUser($user, $minLen, $maxLen)
  41.                 {  
  42.    
  43.                         $check = $this->initQuery($user);
  44.  
  45.                         if((strlen($user) <= $minLen) || (strlen($user) >= $maxLen))
  46.                         {  
  47.  
  48.                                 $_SESSION['login']['error']['user'] = "Your username needs to be between $minLen and $maxLen";
  49.                                 exit;
  50.  
  51.                         } elseif($check == false) {
  52.    
  53.                                 $_SESSION['login']['error']['user'] = "Invalid username or password";
  54.                                 exit;
  55.  
  56.                         } else {
  57.  
  58.                                 if(isset($_SESSION['login']['error']['user']))
  59.                                 {  
  60.                                         unset($_SESSION['login']['error']['user']);
  61.                                 }  
  62.  
  63.                                 $_SESSION['store']['user'] = $user;
  64.  
  65.                         }  
  66.  
  67.                 }  
  68.                 public function validatePass($user, $pass, $minLen, $maxLen)
  69.                 {  
  70.    
  71.                         $check = $this->initQuery($user);
  72.  
  73.                         if((strlen($pass) <= $minLen) || (strlen($pass) >= $maxLen)
  74.                         {
  75.  
  76.                                 $_SESSION['login']['error']['pass'] = "Your password needs to be between $minLen and $maxLen";
  77.                                 exit;
  78.  
  79.                         } elseif ($check == false) {
  80.  
  81.                                 $_SESSION['login']['error']['pass'] = "Invalid username or password";
  82.  
  83.                         } else {
  84.  
  85.                                 if(isset($_SESSION['login']['error']['pass']))
  86.                                 {
  87.                                         unset($_SESSION['login']['error']['pass']);
  88.                                 }
  89.  
  90.                         }
  91.  
  92.                 }
  93.  
  94.                 private function saltPass($user, $pass)
  95.                 {
  96.  
  97.                         $check = $this->initQuery($user);
  98.  
  99.                             $password = $pass;
  100.                             $salt = sha1(md5($check['created']));
  101.                             $password = md5($password.$salt);
  102.  
  103.                 }
  104.  
  105.         }
  106.  
  107. ?>
Add Comment
Please, Sign In to add comment