Guest User

Untitled

a guest
Dec 1st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. function user_login($username, $password)
  2. {
  3. // Try and get the salt from the database using the username
  4. $query = "SELECT `salt` FROM `bombay_customers` WHERE `user-name`='$username' LIMIT 1";
  5. $result = mysql_query($query);
  6. if (mysql_num_rows($result) > 0)
  7. {
  8. // Get the user
  9. $user = mysql_fetch_array($result);
  10. // Using the salt, encrypt the given password to see if it
  11. // matches the one in the database
  12. $encrypted_pass = md5(md5($password).$user['salt']);
  13.  
  14. // Try and get the user using the username & encrypted pass
  15. $query = "SELECT `id`, `user-name` FROM `bombay_customers` WHERE `user-name`='$username' AND `password`='$encrypted_pass'";
  16. $result = mysql_query($query);
  17. if (mysql_num_rows($result) > 0)
  18. {
  19. $user = mysql_fetch_array($result);
  20.  
  21. // Now encrypt the data to be stored in the session
  22. $encrypted_id = md5($user['id']);
  23. $encrypted_name = md5($user['user-name']);
  24. // Store the data in the session
  25. $_SESSION['userid'] = $user['id'];
  26. $_SESSION['username'] = $user['user-name'];
  27. $_SESSION['encrypted_id'] = $encrypted_id;
  28. $_SESSION['encrypted_name'] = $encrypted_name;
  29.  
  30. // Return ok code
  31. return true;
  32. }
  33. else
  34. {
  35. return false;
  36. }
  37. }
  38. else
  39. {
  40. return false;
  41. }
  42. }
Add Comment
Please, Sign In to add comment