Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. <?php
  2.  
  3. include_once "db.php";
  4. session_start();
  5. $pass=$username="";
  6. $login_err=$match_err="";
  7. if(isset($_POST['password'])) {
  8. //trim and anti-special the pass
  9. if (!preg_match("[$&+,:;=?@#|'<>.-^/*()%!]", trim($_POST['usn']))){
  10. $username=trim($_POST['usn']);
  11. } else {
  12. $login_err="tokios paskyros nera";
  13. }
  14.  
  15. }
  16.  
  17.  
  18. if(isset($_POST['usn'])){
  19. ///trim and anti-spec it
  20. if (!preg_match("[$&+,:;=?@#|'<>.-^/*()%!]", trim($_POST['password']))){
  21. $pass=trim($_POST['password']);
  22. };
  23. }
  24. $use=$db->real_escape_string($username);
  25. $query= "SELECT * FROM prisijungimai WHERE username = '$use'";
  26.  
  27. if(isset($pass) && !empty($_POST['pass'])) {
  28. if ($results = $db->query($query)) {
  29. //getting just one row matched to according UNIQUE username and fetching details needed to login
  30. $row = $db->fetch_assoc();
  31. $username = $row['username'];
  32. $c_pass = $row['Pass'];
  33. $lvl = $row["grp"];
  34.  
  35. if ($pass == $c_pass) {
  36. //LOGIN
  37. $_SESSION['lvl'] = $lvl;
  38. $_SESSION['user'] = $username;
  39. header('location:nav.php');
  40. } else { //Wrong Password
  41. $match_err = "neteisingas vartotojo slaptazodis";
  42. }
  43. }
  44. { //if assoc is empty(no result)
  45. $login_err = "tokio vartotojo nera";
  46. }
  47. }
  48.  
  49.  
  50.  
  51. ?>
  52.  
  53.  
  54. <!DOCTYPE html>
  55. <html lang="en">
  56. <head>
  57. <meta charset="UTF-8">
  58. <title>Login</title>
  59. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
  60. <style type="text/css">
  61. body{ font: 14px sans-serif; }
  62. .wrapper{ width: 350px; padding: 20px; }
  63. </style>
  64. </head>
  65. <body>
  66. <div class="wrapper">
  67. <h2>Login</h2>
  68. <p>Please fill in your credentials to login.</p>
  69. <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
  70. <div class="form-group <?php echo (!empty($login_err)) ? 'has-error' : ''; ?>">
  71. <label>Username</label>
  72. <input type="text" name="usn" class="form-control">
  73. <span class="help-block"><?php echo $login_err; ?></span>
  74. </div>
  75. <div class="form-group <?php echo (!empty($match_err)) ? 'has-error' : ''; ?>">
  76. <label>Password</label>
  77. <input type="password" name="password" class="form-control">
  78. <span class="help-block"><?php echo $match_err; ?></span>
  79. </div>
  80. <div class="form-group">
  81. <input type="submit" class="btn btn-primary" value="Login">
  82. </div>
  83. <p>Don't have an account? <a href="register.php">Sign up now</a>.</p>
  84. </form>
  85. </div>
  86.  
  87.  
  88.  
  89. </body>
  90.  
  91. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement