This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.html
executable file
·52 lines (52 loc) · 1.79 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Password</title>
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@600;900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<link rel="icon" href="padlock.svg" type="image/svg+xml">
<script type="text/javascript" src="sha256.js"></script>
</head>
<body>
<form id="form">
<p id="message">Please enter your password.</p>
<input type="password" placeholder="password" id="password">
</form>
<script>
function hash(text) {
const sha = new jsSHA('SHA-256', 'TEXT');
sha.update(text);
return sha.getHash('HEX');
}
function auth(password) {
const url = hash(password);
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.send();
xhr.onload = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
window.location = url;
} else {
const message = document.getElementById('message');
const input = document.getElementById('password');
message.innerHTML = 'Wrong password! Try again.';
input.value = '';
}
};
xhr.onerror = function () {
const message = document.getElementById('message');
message.innerHTML = 'Sorry, ERROR !';
};
}
const form = document.getElementById('form');
form.addEventListener('submit', function (event) {
const password = document.getElementById('password').value;
auth(password);
event.preventDefault();
});
</script>
</body>
</html>