Advertisement
Guest User

Untitled

a guest
May 15th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php
  2.  
  3. require './common.php';
  4.  
  5. session_start(); //must call session_start before using any $_SESSION variables
  6.  
  7.  
  8. if(isset($_GET['logout'])) { // Logout?
  9.     logout();
  10. }
  11.  
  12.  
  13. if (isset($_POST['submit'])) { // if page is not submitted to itself echo the form
  14.  
  15.     $username = $_POST['username'];
  16.  
  17.     $username = mysql_real_escape_string($username);
  18.  
  19.     $query = $db->SQL("SELECT password, salt FROM users WHERE username = '$'", $username);
  20.  
  21.     if(empty($query)) //no such user exists
  22.     {
  23.         echo "No Such User Exists";
  24.         die();
  25.     }
  26.    
  27.     $userData = $query[0];
  28.     $hash = sha1( $userData['salt'] . sha1($_POST['password']) );
  29.  
  30.     if($hash != $userData['password']) //incorrect password
  31.     {
  32.         echo "Incorrect Password";
  33.         die();
  34.     }
  35.     else
  36.     {
  37.         validateUser(); //sets the session data for this user
  38.     }
  39.  
  40.     header('Location: index.php');
  41.     //redirect to another page or display "login success" message
  42.    
  43. }
  44.  
  45. // Here would normally be where the template file executes, but because this is just sample code, the form is included below.
  46.  
  47. ?>
  48.  
  49. <form name="register" action="login.php" method="post">
  50.     Username: <input type="text" name="username" maxlength="30" />
  51.     Password: <input type="password" name="password" />
  52.     <input type="submit" name="submit" value="Login" />
  53. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement