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