Advertisement
Guest User

Untitled

a guest
Apr 29th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.51 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'config.php';
  4.  
  5. function get_value($str) {
  6.     return base64_decode($str);
  7. }
  8.  
  9. function login($username, $password) {
  10.     global $db;
  11.     $query = "SELECT user_id FROM users WHERE username='$username' and password='$password'";
  12.     $result = mysqli_query($db, $query);
  13.     if ($result && (mysqli_num_rows($result)>0)) {
  14.             return TRUE;
  15.     }
  16.     return FALSE;
  17. }
  18.  
  19. $username  = get_value($_POST['username']);
  20. // We store the password in plaintext to keep the homework's code short.
  21. // For anything even remotely real, use a proper password storage scheme.
  22. $password  = get_value($_POST['password']);
  23.  
  24. if(empty($username) || empty($password)) {
  25.     $alert = "Please insert your credentials!";
  26.     $login_ok = FALSE;
  27. } else {
  28.     $login_ok = login($username, $password);
  29.     if(!$login_ok) {
  30.         $alert = "Wrong username or password!";
  31.     }
  32. }
  33. ?>
  34.  
  35. <!doctype html>
  36. <html lang="en">
  37. <head>
  38.     <title>Little Bobby Tables</title>
  39.     <link href="bootstrap.min.css" rel="stylesheet">
  40.     <meta charset="utf8">
  41.     <meta name="viewport" content="width=device-width, initial-scale=1">
  42. </head>
  43. <body>
  44. <div class="container" style="max-width: 600px; margin-top: 2em;">
  45.  
  46.     <?php if($alert !== NULL && trim($alert) !== ""); { ?>
  47.     <div class="alert alert-danger"><?php echo $alert; ?></div>
  48.     <?php } ?>
  49.  
  50.  
  51.     <?php if($login_ok === TRUE) { ?>
  52.         <h1>Hi <?php echo htmlentities($username); ?>! You are logged in!</h1>
  53.         <h2>We have some secret information ready for you...</h2>
  54.         <p>Here it is: <b><?php echo htmlentities(get_secret($username)); ?></b></p>
  55.         <img style='width: 100%' src='exploits_of_a_mom.png'>
  56.     <?php } ?>
  57.  
  58.     <?php if($login_ok != TRUE) { ?>
  59.         <h1 style="text-align: center;">Access Restricted</h1>
  60.         <form method="post" id="login_form" class="form-horizontal" style="max-width: 75%; margin: 0 auto;">
  61.             <div class="form-group">
  62.                 <label for="name">Name: </label>
  63.                 <input type="text" name="username" class="form-control">
  64.             </div>
  65.             <div class="form-group">
  66.                 <label for="name">Password: </label>
  67.                 <input type="password" name="password" class="form-control">
  68.             </div>
  69.             <input type="submit" value="Login" class="btn btn-primary" style="display: block; margin: 0 auto; min-width: 50%">
  70.         </form>
  71.     <?php } ?>
  72.  
  73.     <script type="text/javascript" src="formutils.js"></script>
  74.  
  75. </div>
  76. </body>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement