Advertisement
Guest User

Untitled

a guest
Jul 18th, 2011
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.03 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.     Longhorn Linux Member System - By Cuonic
  5.     Uses MySQL Database. Interaction via MySQLi
  6.     Enables Login and displaying user info on site
  7. */
  8.  
  9. session_start();
  10.  
  11. include("mysql.php"); // MySQL Connection. Establishes connection successfully
  12.  
  13. // Function defining :
  14.  
  15. function randstr()
  16. {
  17.     $characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  18.     $randstring = '';
  19.     for ($i = 0; $i <= 15; $i++)
  20.     {
  21.         $randstring = $characters[rand(0, strlen($characters))];
  22.     }
  23.     return $randstring;
  24. }
  25.  
  26. // Error / Success message array defining :
  27.  
  28. $errormsg = array();
  29. $successmsg = array();
  30.  
  31. if($_REQUEST['action'])
  32. {
  33.     $action = $_REQUEST['action'];
  34.    
  35.     switch($action)
  36.     {
  37.         case '1' :
  38.             $username = $_REQUEST['username'];
  39.             $password = $_REQUEST['password'];
  40.            
  41.             if(strlen($username) == 0) { $errormsg[] = "Username field is empty !"; }
  42.             elseif(strlen($username) > 30) { $errormsg[] = "Username is too long !"; }
  43.             elseif(strlen($username) < 3) { $errormsg[] = "Username is too short !"; }
  44.             if(strlen($password) == 0) { $errormsg[] = "Password field is empty !"; }
  45.             elseif(strlen($password) > 30) { $errormsg[] = "Password is too long !"; }
  46.             elseif(strlen($password) < 5) { $errormsg[] = "Password is too short !"; }
  47.            
  48.             if(count($errormsg) == 0)
  49.             {
  50.                 $password = hash("SHA512", $password);
  51.            
  52.                 $query = $mysqli->prepare("SELECT password FROM users WHERE username=?");
  53.                 $query->bind_param("s", $username);
  54.                 $query->execute();
  55.                 $query->bind_result($db_password);
  56.                 $query->fetch();
  57.                 $count = $query->num_rows;
  58.            
  59.                 if($count == 0) { $errormsg[] = "Username is incorrect !"; } // gets to here, no rows detected for correct username D:
  60.                 else
  61.                 {
  62.                     if($password == $db_password)
  63.                     {
  64.                         $_SESSION['isauth'] = 1;
  65.                         $_SESSION['username'] = $username;
  66.                     }
  67.                     else
  68.                     {
  69.                         $errormsg[] = "Password is incorrect !";
  70.                     }
  71.                 }
  72.             }
  73.             break;
  74.            
  75.         default :
  76.             $errormsg[] = "Invalid Action ID !";
  77.             break;
  78.     }
  79. }
  80.  
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement