Advertisement
Guest User

Untitled

a guest
May 17th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php
  2.  
  3. // Include global variables and initiate a database connection
  4. require('./connect.php');
  5.  
  6. // Escape the email address so the DB is hacker-safe
  7. $email_address = mysql_real_escape_string($_POST['email_address']);
  8.  
  9. // Search the DB for any members with the submitted email address
  10. $result = mysql_query("SELECT * FROM runningclub WHERE email_address='$email_address'");
  11.  
  12. // Set $pass to false as a default value
  13. $pass = false;
  14.  
  15. // If one record is returned..
  16. if (mysql_num_rows($result) == 1) {
  17.     // Populate $user with an associative array of values
  18.     $user = mysql_fetch_assoc($result);
  19.    
  20.     // Hash up the submitted password in the same way those in the DB are hashed
  21.     $password = sha1(sha1($_POST['password']) . PASSWORD_SALT);
  22.    
  23.     // Check the submitted password and the password in the DB match
  24.     if ($password == $user['password']) {
  25.         // They match, set cookies and redirect to the members area
  26.         setcookie('email', $user['email_address'], time()+60*60*2)
  27.         setcookie('password', sha1($user['password'] . COOKIE_SALT), time()+60*60*2)
  28.         header('Location: membersarea.php');
  29.        
  30.         // Set $pass to true so the conditional below does not evaluate
  31.         $pass = true;
  32.     }
  33. }
  34.  
  35. // If no users were found or the passwords did not match...
  36. if (!$pass) {
  37.     // Let the user know
  38.     echo "Wrong Username or Password, please press the back button in your browser and try again";
  39. }
  40.  
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement