Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2017
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.75 KB | None | 0 0
  1. <html>
  2. <head>
  3.     <title>Code snippet forum-Login page</title>
  4.   <script src='https://www.google.com/recaptcha/api.js'></script>
  5.     <?php
  6.     session_start();
  7.     session_destroy();
  8.     $link = mysqli_connect("127.0.0.1", "root", "", "delta");
  9.     require_once "recaptchalib.php";
  10.     session_start();    
  11.     if(!$link){
  12.      echo "Could not connect";
  13.      echo mysqli_error($link);
  14.     }
  15.     else{
  16.      echo "Sucesssfully connected";
  17.      if(isset($_POST["login"])){
  18.         if(isset($_POST["username"])){
  19.             $username = mysqli_real_escape_string($link,$_POST["username"]);
  20.            $username = stripslashes($username);
  21.          }
  22.         if(isset($_POST["password"])){
  23.               $password = mysqli_real_escape_string($link,$_POST["password"]);
  24.            $password = stripslashes($password);
  25.            
  26.             }
  27.        $secret = "6Le_iScUAAAAADkT6a-7dPnEBjWKhmMls2tOxJql";
  28.  
  29.      // empty response
  30.        $response = null;
  31.  
  32.      // check secret key
  33.         $reCaptcha = new ReCaptcha($secret);
  34.          if ($_POST["g-recaptcha-response"]) {
  35.          $response = $reCaptcha->verifyResponse(
  36.           $_SERVER["REMOTE_ADDR"],
  37.           $_POST["g-recaptcha-response"]
  38.         );
  39.       }
  40.         $password_hash = hash('md5',$password);
  41.         $query = "SELECT * FROM user_info WHERE username = '".$username."' AND password = '".$password_hash."'";
  42.         $sql = mysqli_query($link,$query);      
  43.         $rows = mysqli_num_rows($sql);
  44.         if($rows==1&&$response != null&&$response->success){
  45.            echo "  Sucessfully logged in";
  46.             $_SESSION["username"] = $username;
  47.             header("Location: insert.php");
  48.         }
  49.         else{
  50.             echo "  Invalid username or password";
  51.         }
  52.        
  53.       }
  54.      }
  55.     ?>
  56.  
  57.  
  58. </head>
  59. <style type="text/css">
  60.    .login{
  61.      border: 2px solid black;
  62.      border-radius: 6px 6px 6px 6px;
  63.      padding: 15px 15px 15px 15px;
  64.      margin right: 400px;
  65.      margin-top: 210px;
  66.      margin-left: 310px;
  67.      width: 450px;
  68.      font-size: 20px;
  69.    }
  70.    body {
  71.     font: 13px/20px "Lucida Grande", Tahoma, Verdana, sans-serif;
  72.     color: #404040;
  73.     background: #0ca3d2;
  74.    }
  75.    
  76.   </style>
  77. <body>
  78.   <div class = "login">
  79.   <form method = "POST" >
  80.     <p>Username: <input type = "text" name = "username" placeholder = 'Enter the username'></p>
  81.     <p>Password: <input type = "text" name = "password" placeholder = "Enter the password"></p>
  82.     <input type = "submit" name = "login" value = "Login">
  83.     <div class="g-recaptcha" data-sitekey="6Le_iScUAAAAAD2UsWWJ0fxKT2LtXk-MXNxR6JXS"></div>
  84.   </form>
  85.   <a href = "register.php">Click here to register</a>
  86. </div>
  87. <a href="list.php">This is the list of all snippets</a>
  88. </body>
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement