forked from joereddington/reasdiary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
122 lines (104 loc) · 4.98 KB
/
main.js
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
import { top1000Passwords } from "./top100passwords.js";
const currentYear = new Date().getFullYear();
// Function to generate the password based on rules
function generatePassword(dogName, requireCapital = false, requireNumber = false, requireSpecialChar = false) {
let password = dogName;
if (requireCapital) password = password.charAt(0).toUpperCase() + password.slice(1);
if (requireNumber) password += currentYear;
if (requireSpecialChar) password += '!';
return password;
}
const dogName = 'sparkles';
const correctPassword = generatePassword(dogName, true, true, true);
// Utility function to display messages
function displayMessage(element, text, color) {
element.textContent = text;
element.style.color = color;
}
// Handle incorrect password responses
function handleIncorrectPassword(responseElement) {
displayMessage(responseElement, 'Error: Incorrect password. Please try again.', 'red');
}
// Check if password is in the top 1000 list
function handleCommonPasswordCheck(password, responseElement) {
const passwordIndex = top1000Passwords.indexOf(password);
if (passwordIndex !== -1) {
displayMessage(responseElement,
`Good guess! That is the ${passwordIndex + 1}${getOrdinalSuffix(passwordIndex + 1)} most common password according to Wikipedia!`,
'orange'
);
return true;
}
return false;
}
// Function to get ordinal suffix (1st, 2nd, 3rd, etc.)
function getOrdinalSuffix(rank) {
const j = rank % 10, k = rank % 100;
if (j === 1 && k !== 11) return 'st';
if (j === 2 && k !== 12) return 'nd';
if (j === 3 && k !== 13) return 'rd';
return 'th';
}
// Main event listener for login form
document.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('password-form');
const input = document.getElementById('password');
const usernameInput = document.getElementById('username');
const response = document.getElementById('response');
// 2FA Elements
const twoFAContainer = document.createElement('div');
twoFAContainer.style.display = 'none';
twoFAContainer.innerHTML = `
<label for="twofa-code">Enter 2FA Code:</label>
<input type="text" id="twofa-code" placeholder="6-digit code" maxlength="6">
<button id="submit-2fa">Submit Code</button>
`;
form.appendChild(twoFAContainer);
form.addEventListener('submit', (event) => {
event.preventDefault();
const password = input.value.trim();
const username = usernameInput.value.trim().toLowerCase();
// Username checks
if (username === "play.poet.wedge") {
displayMessage(response, "Incorrect username or password.", "red");
return;
}
if (username === "madlad2329") {
if (password === "password") {
// Show 2FA input field
twoFAContainer.style.display = 'block';
displayMessage(response, "Two-Factor Authentication required. Please enter the 6-digit code.", "orange");
// Handle 2FA submission
document.getElementById('submit-2fa').addEventListener('click', function() {
const twoFACode = document.getElementById('twofa-code').value.trim();
if (twoFACode.length === 6) {
displayMessage(response, "Incorrect 2FA code. Please try again.", "red");
} else {
displayMessage(response, "Please enter a valid 6-digit 2FA code.", "red");
}
});
} else {
handleIncorrectPassword(response);
}
return;
}
if (username === "rea_gymnastics") {
if (password === correctPassword) {
displayMessage(response, "Access Granted! Welcome.", "green");
} else if (password.toLowerCase() === correctPassword.toLowerCase()) {
displayMessage(response, "That is a really interesting guess, but maybe the diary needs a capital letter?", "orange");
} else if (handleCommonPasswordCheck(password, response)) {
return;
} else if (password.toLowerCase().includes("2025")) {
displayMessage(response, "Interesting choice! You included the year. Lots of people do that when they have to change their password a lot. Often computers want you to add a punctuation character as well...", "orange");
} else if (password.toLowerCase().includes(dogName.toLowerCase())) {
displayMessage(response, `Interesting choice! You included the dog's name, "${dogName}". But maybe Rea has to change the password at least once a year.`, "orange");
} else {
handleIncorrectPassword(response);
}
return;
}
// Default case for unrecognized usernames
displayMessage(response, "That username doesn't exist, please try another.", "red");
});
});