Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 KB | None | 0 0
  1. <?php
  2.  session_start();
  3. if (isset($_POST["submit"])) {
  4.     //verbind met database
  5.     require("includes/connect.php");
  6.  
  7.    //controleer of gegevens kloppen
  8.    $username =  $_POST["username"];
  9.    
  10.     $stmt = $conn->prepare("SELECT `id`, `password` FROM users WHERE username = ?");
  11.     $stmt->bind_param("s", $username);
  12.     $stmt->execute();
  13.     $res = $stmt->get_result();
  14.     $row = $res->fetch_all();
  15.  
  16.     if (isset($row[0][1])) {
  17.  
  18.     $correctpassword = $row[0][1];
  19.     //var_dump($correctpassword);
  20.     //var_dump(password_verify($_POST["password"],$correctpassword));
  21.  
  22.     if (password_verify($_POST["password"],$correctpassword)) {
  23.        
  24.         $_SESSION["session_id"] = session_id();
  25.         $_SESSION["user_id"] = $row[0][0];
  26.         $_SESSION["user"] = $_POST["username"];
  27.         //die("Je bent inlgelogt!<br>Klik <a href=\"index.php\">hier</a> om terug te gaan");
  28.         header("location: index.php");
  29.     }
  30.     else{
  31.         echo("<span class='error'>Username or password in incorrect.</span>");
  32.     }
  33. /*
  34.     if ($correctpassword == password_hash($_POST["password"],PASSWORD_DEFAULT) {
  35.         echo "wachtwoord goed";
  36.     }
  37. */
  38.     }
  39.     else {
  40.         echo("Username or password in incorrect.");
  41.     }
  42.    
  43.    
  44.  
  45.  
  46.  
  47.    
  48.  
  49.  
  50.    
  51.    
  52. }
  53.  
  54.  
  55. ?>
  56. <!DOCTYPE html>
  57. <html>
  58. <head>
  59.     <meta charset="utf-8" />
  60.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  61.     <title>Login</title>
  62.     <meta name="viewport" content="width=device-width, initial-scale=1">
  63.     <link rel="stylesheet" type="text/css" media="screen" href="styles/main.css" />
  64.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  65.     <script src="main.js"></script>
  66. </head>
  67. <body>
  68.     <form method="POST" action="">
  69.         <h1>Login</h1>
  70.         <input type="text" name="username" placeholder="username" maxlength="50" required><br>
  71.         <input type="password" name="password" placeholder="password" required><br>
  72.         <input type="submit" name="submit">
  73.  
  74.     </form>
  75.    
  76. </body>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement