Advertisement
metalx1000

Basic Login Form for Apache

Aug 27th, 2024
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4.   <head>
  5.     <title>Login</title>
  6.     <meta charset="utf-8">
  7.     <meta name="viewport" content="width=device-width, initial-scale=1">
  8.     <style>
  9.     @media only screen and (min-width: 600px) {
  10.     body {
  11.     margin-right: 200px;
  12.     margin-left: 200px;
  13.     margin-top: 20px;
  14.     }
  15.     }
  16.     </style>
  17.   </head>
  18.  
  19.   <body>
  20.     <form id="login">
  21.       <label for="user">User: </label>
  22.       <input type="text" name="user" id="user">
  23.       <br>
  24.       <label for="password">Password</label>
  25.       <input type="password" name="password" id="password">
  26.     </form>
  27.     <button type="button" onclick="login()">Login</button>
  28.     <div id="output"></div>
  29.     <a target="_blank" href="https://pastebin.com/tvnmSB6E">Click Here For Server Setup</a>
  30.   </body>
  31.   <script>
  32. let output = document.querySelector("#output");
  33.  
  34. function login(){
  35.   let user = document.querySelector("#user");
  36.   let password = document.querySelector("#password");
  37.   if (user.value == "" || password.value == ""){
  38.     output.innerHTML = "Username and Password Required";
  39.     return;
  40.   }
  41.  
  42.   get(`private/index.html`, user.value, password.value,  function(data){
  43.     output.innerHTML = data;
  44.   });
  45. }
  46.  
  47. function get(url, user, password, success) {
  48.  
  49.   var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  50.   xhr.open('GET', url);
  51.   xhr.onreadystatechange = function() {
  52.     if (xhr.readyState>3 && xhr.status==200) success(xhr.responseText);
  53.   };
  54.   xhr.setRequestHeader("Authorization", "Basic " + btoa(user + ":" + password), 'X-Requested-With', 'XMLHttpRequest');
  55.   xhr.send();
  56.   return xhr;
  57. }
  58.   </script>
  59. </html>
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement