Guest User

Untitled

a guest
Dec 4th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. html>
  2. <body>
  3. <?php
  4. function Login()
  5. {
  6. if(empty($_POST['username']))
  7. {
  8. echo "UserName is empty!";
  9.  
  10. return false;
  11. }
  12.  
  13. if(empty($_POST['password']))
  14. {
  15. echo "Password is empty!";
  16.  
  17. return false;
  18. }
  19.  
  20. $username = trim($_POST['username']);
  21. $password = trim($_POST['password']);
  22.  
  23. if(!$this->CheckLoginInDB($username,$password))
  24. {
  25. return false;
  26. }
  27.  
  28. session_start();
  29.  
  30. $_SESSION[$this->GetLoginSessionVar()] = $username;
  31.  
  32. return true;
  33. }
  34.  
  35. function DBLogin()
  36. {
  37.  
  38. $ligacao= mysql_connect("localhost","root","");
  39. if(!$ligacao){
  40. echo "<p>Falha na ligação à Base de dados.";
  41. exit;
  42. }
  43. mysql_select_db("book",$ligacao);
  44. }
  45.  
  46.  
  47. function CheckLoginInDB($username,$password)
  48. {
  49. if(!$this->DBLogin())
  50. {
  51. $this->HandleError("Database login failed!");
  52. return false;
  53. }
  54. $username = $this->SanitizeForSQL($username);
  55. $pwdmd5 = md5($password);
  56. $qry = "Select name, email from $this->tablename ".
  57. " where username='$username' and password='$password' ";
  58.  
  59. $result = mysql_query($qry,$this->connection);
  60.  
  61. if(!$result || mysql_num_rows($result) <= 0)
  62. {
  63. $this->HandleError("Error logging in. ".
  64. "The username or password does not match");
  65. return false;
  66. }
  67. return true;
  68. }
  69. ?>
  70. </body>
  71. </html>
Add Comment
Please, Sign In to add comment