|
| 1 | +<html> |
| 2 | +<head> |
| 3 | + <title>HIBQ</title> |
| 4 | + <style> |
| 5 | + body { |
| 6 | + font-family: Arial, sans-serif; |
| 7 | + max-width: 800px; |
| 8 | + margin: 0 auto; |
| 9 | + text-align: center; |
| 10 | + } |
| 11 | + form { |
| 12 | + margin: 20px 0; |
| 13 | + } |
| 14 | + input[type="password"] { |
| 15 | + font-size: 18px; |
| 16 | + padding: 10px; |
| 17 | + border: 1px solid #ccc; |
| 18 | + border-radius: 4px; |
| 19 | + box-sizing: border-box; |
| 20 | + } |
| 21 | + input[type="text"] { |
| 22 | + font-size: 18px; |
| 23 | + padding: 10px; |
| 24 | + border: 1px solid #ccc; |
| 25 | + border-radius: 4px; |
| 26 | + box-sizing: border-box; |
| 27 | + } |
| 28 | + button[type="button"] { |
| 29 | + font-size: 18px; |
| 30 | + padding: 10px 20px; |
| 31 | + background-color: #4CAF50; |
| 32 | + color: white; |
| 33 | + border: none; |
| 34 | + border-radius: 4px; |
| 35 | + cursor: pointer; |
| 36 | + } |
| 37 | + button[type="button"]:hover { |
| 38 | + background-color: #45a049; |
| 39 | + } |
| 40 | + .result { |
| 41 | + margin: 20px 0; |
| 42 | + font-size: 18px; |
| 43 | + } |
| 44 | + .result.safe { |
| 45 | + color: green; |
| 46 | + } |
| 47 | + .result.unsafe { |
| 48 | + color: red; |
| 49 | + } |
| 50 | + </style> |
| 51 | +</head> |
| 52 | +<body> |
| 53 | + <h1>HIBQ</h1> |
| 54 | + <form> |
| 55 | + API Key: <input type="password" id="key" value="xxx"> |
| 56 | + </form> |
| 57 | + resultKey: <p id="resultKey"></p> |
| 58 | + |
| 59 | + <p>Enter a password to check if it has been compromised in a data breach:</p> |
| 60 | + <form> |
| 61 | + <input type="password" id="password"> |
| 62 | + <button type="button" onclick="checkPassword()">Check Password</button> |
| 63 | + </form> |
| 64 | + resultPassword: <p id="resultPassword"></p> |
| 65 | + |
| 66 | + <form> |
| 67 | + <input type="text" id="account"> |
| 68 | + <button type="button" onclick="checkAccount()">Check Account</button> |
| 69 | + </form> |
| 70 | + resultAccount: <p id="resultAccount"></p> |
| 71 | + |
| 72 | + <form> |
| 73 | + <label for="email">Email:</label> |
| 74 | + <input type="email" id="email" name="email"> |
| 75 | + <button type="button" onclick="checkEmail()">Check</button> |
| 76 | + </form> |
| 77 | + <p id="result"></p> |
| 78 | + |
| 79 | + <script> |
| 80 | + function checkPassword() { |
| 81 | + // Get the API key |
| 82 | + var key = document.getElementById("key").value; |
| 83 | + |
| 84 | + // Get the password from the input field |
| 85 | + var password = document.getElementById('password').value; |
| 86 | + |
| 87 | + // Use the Have I Been Pwned API to check if the password has been compromised |
| 88 | + fetch('https://api.pwnedpasswords.com/range/' + password.substring(0, 5), { |
| 89 | + // "method": "GET", |
| 90 | + "headers": { |
| 91 | + "Access-Control-Allow-Origin": "*", |
| 92 | + "Access-Control-Allow-Headers": "mode", |
| 93 | + "Access-Control-Allow-Methods": "*", |
| 94 | + "mode": "no-cors", |
| 95 | + "hibp-api-key": key |
| 96 | + } |
| 97 | + }) |
| 98 | + .then(response => response.text()) |
| 99 | + .then(data => { |
| 100 | + // Split the response into lines |
| 101 | + var lines = data.split('\n'); |
| 102 | + |
| 103 | + // Search for the password hash in the response |
| 104 | + for (var i = 0; i < lines.length; i++) { |
| 105 | + var line = lines[i]; |
| 106 | + var hash = line.substring(0, 35); |
| 107 | + var count = line.substring(36); |
| 108 | + if (password.toUpperCase() == hash) { |
| 109 | + // If the password hash is found, display the result |
| 110 | + document.getElementById('resultPassword').innerHTML = 'This password has been compromised ' + count + ' times. It is not safe to use.'; |
| 111 | + return; |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + // If the password hash is not found, display a message saying the password is safe to use |
| 116 | + document.getElementById('resultPassword').innerHTML = 'This password has not been compromised. It is safe to use.'; |
| 117 | + document.getElementById('resultKey').innerHTML = 'The API Key you entered:' + key; |
| 118 | + }); |
| 119 | + } |
| 120 | + function checkAccount() { |
| 121 | + // Get the API key |
| 122 | + var key = document.getElementById("key").value; |
| 123 | + |
| 124 | + // Get the account from the input field |
| 125 | + var account = document.getElementById('account').value; |
| 126 | + |
| 127 | + fetch("https://haveibeenpwned.com/api/v3/breachedaccount/" + account + "?truncateResponse=false", { |
| 128 | + "method": "GET", |
| 129 | + "headers": { |
| 130 | + "Access-Control-Allow-Origin": "*", |
| 131 | + "Access-Control-Allow-Headers": "mode", |
| 132 | + "Access-Control-Allow-Methods": "*", |
| 133 | + "mode": "no-cors", |
| 134 | + "hibp-api-key": key |
| 135 | + } |
| 136 | + }) |
| 137 | + .then(response => { |
| 138 | + console.log(response); |
| 139 | + }) |
| 140 | + .catch(err => { |
| 141 | + console.error(err); |
| 142 | + }); |
| 143 | + } |
| 144 | + |
| 145 | + function checkEmail() { |
| 146 | + // Get the API key |
| 147 | + var key = document.getElementById("key").value; |
| 148 | + |
| 149 | + var email = document.getElementById("email").value; |
| 150 | + var xhr = new XMLHttpRequest(); |
| 151 | + xhr.open("GET", "https://haveibeenpwned.com/api/v3/breachedaccount/" + email + "?truncateResponse=false"); |
| 152 | + xhr.setRequestHeader("hibp-api-key", key); |
| 153 | + xhr.onload = function() { |
| 154 | + var resultElement = document.getElementById("result"); |
| 155 | + if (xhr.status === 200) { |
| 156 | + var breaches = JSON.parse(xhr.responseText); |
| 157 | + if (breaches.length > 0) { |
| 158 | + resultElement.innerHTML = "The email address " + email + " has been compromised in the following breaches: " + breaches.map(b => b.Name).join(", "); |
| 159 | + } else { |
| 160 | + resultElement.innerHTML = "The email address " + email + " has not been found in any breaches."; |
| 161 | + } |
| 162 | + } else { |
| 163 | + resultElement.innerHTML = "An error occurred: " + xhr.status + " " + xhr.statusText; |
| 164 | + } |
| 165 | + }; |
| 166 | + xhr.send(); |
| 167 | + } |
| 168 | + </script> |
| 169 | + </body> |
| 170 | + </html> |
0 commit comments