Guest User

Untitled

a guest
Mar 9th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. <form class="form login" id="log_user">
  2.  
  3. <input id="login__username" type="text" name="username" class="form__input" placeholder="Username" required>
  4.  
  5. <input id="login__password" type="password" name="password" class="form__input" placeholder="Password" required>
  6.  
  7. <input type="submit" value="Log In">
  8.  
  9. </form>
  10.  
  11. $(document).ready(function(){
  12. $("#log_user").submit(function(){
  13. $.ajax({
  14. type:"POST",
  15. data:{
  16. username : $("#login__username").val(),
  17. password : $("#login__password").val()
  18. },
  19. url:"log_user.php",
  20. success: function(data){
  21. if(data == 'Success'){
  22. alert('Login Passw correct');
  23. }
  24. else{
  25. alert(data);
  26. }
  27. },
  28. error: function(){
  29. alert('something went wrong');
  30. }
  31. });
  32. return false;
  33. });});
  34.  
  35. <?php
  36.  
  37. foreach(file('passwd.txt') as $line) {
  38.  
  39. if(empty($line)) continue;
  40.  
  41. $lineArray = explode(':', $line);
  42. $username = rtrim($lineArray[0]);
  43. $password = rtrim($lineArray[1]);
  44.  
  45. if( isset($_POST['username']) && isset($_POST['password']) ){
  46.  
  47. if($_POST['username'] == $username && $_POST['password'] == $password){
  48. session_start();
  49. $_SESSION['user'] = $username;
  50. echo "Success";
  51. }
  52. else{
  53. echo "Failed";
  54. }
  55. }
  56. }
  57.  
  58. ?>
  59.  
  60. myname:mypassw
  61. myname2:mypassw2
Add Comment
Please, Sign In to add comment