Guest User

Untitled

a guest
Sep 14th, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. login with username or email address in php
  2. $username=$_REQUEST['login'];
  3. $email=$_REQUEST['login'];
  4. $password=$_REQUEST['password'];
  5.  
  6. if($username && $password) {
  7. $query="select * from user_db where username='$username' and password='$password'";
  8. } else if ($email && $password) {
  9. $query="select * from user_db where email='$email' and password='$password'";
  10. }
  11.  
  12. $login=$_REQUEST['login'];
  13. $query = "select * from user_db where ( username='$login' OR email = '$login') and password='$password'"
  14.  
  15. $username=$_REQUEST['login'];
  16. $email=$_REQUEST['login'];
  17.  
  18. $username=$_REQUEST['username'];//I'm assuming your code here was wrong
  19. $email=$_REQUEST['email'];//and that you have three different fields in your form
  20. $password=$_REQUEST['password'];
  21.  
  22. if (validate_username($username)) {
  23. $query="select * from user_db where username='".$username".' and password='".validate_password($password)."'";
  24. } else if (validate_email($email)) {
  25. $query="select * from user_db where email='".$email."' and password='".validate_password($password)."'";
  26. }
  27.  
  28. //... elsewhere...
  29.  
  30. function validate_username(&$username) {
  31. if (strlen($username) <= 1) { return false; }
  32. //return false for other situations
  33. //Does the username have invalid characters?
  34. //Is the username a sql injection attack?
  35. //otherwise...
  36. return true;
  37. }
  38.  
  39. function validate_email(&$email) {
  40. //same deal as with username
  41. }
  42.  
  43. function validate_password(&$password) {
  44. //same deal as with username
  45. }
Add Comment
Please, Sign In to add comment