Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. <?php
  2.  
  3. include 'config.php';
  4.  
  5. $session_username = $_SESSION['username'];
  6.  
  7. if ($_POST['login'])
  8. {
  9. //get form data
  10. $username = ($_POST['username']);
  11. $password = ($_POST['password']);
  12.  
  13. if (!$username||!$password)
  14. echo "Enter a username and password";
  15. else
  16. {
  17. //log in
  18. $login = mysql_query("SELECT * FROM users WHERE username='$username'");
  19. if (mysql_num_rows($login)==0)
  20. echo "No such user";
  21. else
  22. {
  23. while ($login_row = mysql_fetch_assoc($login))
  24. {
  25. //get database password
  26. $password_db = $login_row['password'];
  27.  
  28. //encrypt form password
  29. $password = md5($password);
  30.  
  31. //check password
  32. if ($password!=$password_db)
  33. echo "Incorrect password";
  34.  
  35. else
  36. {
  37. $_SESSION['username']=$username; //assign session
  38. header("Location: index.php"); //refresh
  39. }
  40. }
  41.  
  42.  
  43.  
  44. }
  45. }
  46. }
  47. else
  48. {
  49.  
  50. if (isset($session_username))
  51. {
  52. echo "You are logged in, $session_username. <a href='logout.php'>Log out</a>";
  53. }
  54. else
  55. {
  56. ?> <html>
  57. <head><title>Login Page</title>
  58. <link href="login.css" rel="stylesheet" type="text/css" />
  59. </head>
  60. <body>
  61. <div class="wrapper">
  62. <div id="Box1">
  63. <form action='index.php' method='POST'>
  64. Username:
  65.  
  66. <input type='text' name='username'><p />
  67. Password:
  68.  
  69. <input type='password' name='password'><p />
  70. <input type='submit' name='login' value='Log in'>
  71. </form>
  72. <br />Don't have an account? <a href="regform.html"><b>Register one today</b></a> for free.</div></div>
  73. </body>
  74. </html> <?php
  75. }
  76.  
  77. }
  78.  
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement