-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivate_double_auth.js
36 lines (31 loc) · 1.09 KB
/
activate_double_auth.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
function generateToken() {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const length = 8;
let token = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
token += characters.charAt(randomIndex);
}
return token;
}
function sendToken(user) {
const token = generateToken();
// Send the token to the user using your preferred method
// (e.g., email, SMS, push notification)
console.log(`Token sent to ${user}: ${token}`);
return token;
}
function validateToken(user, enteredToken, storedToken) {
// Compare the entered token with the stored token
return enteredToken === storedToken;
}
const user = {};
const storedToken = sendToken(user);
const enteredToken = prompt('Enter the token you received:');
if (validateToken(user, enteredToken, storedToken)) {
console.log('Authentication successful');
// Proceed with the desired action after successful authentication
} else {
console.log('Authentication failed');
// Handle authentication failure (e.g., display an error message)
}