Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
150 lines (131 loc) · 5.15 KB
/
Copy pathscript.js
File metadata and controls
150 lines (131 loc) · 5.15 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
// For ease of development while working on dashboard.html :
// location.replace('/dashboard/dashboard.html');
// --------------------------------------
// -------- BEGIN AUTH PROCESS ----------
// --------------------------------------
//http get request to database repo via "my json server"
function httpGet(theUrl) {
let xmlHttpReq = new XMLHttpRequest();
xmlHttpReq.open("GET", theUrl, false);
xmlHttpReq.send(null);
return xmlHttpReq.responseText;
}
//import info from database
const credentialsData = httpGet('https://my-json-server.typicode.com/AndrimsDevs/Admin-Central/db');
// convert json data to js readable objects
const credsObj = JSON.parse(credentialsData);
//extract usernames to indiv vars
const usernames = credsObj['usernames'];
const usnmAult = usernames['ault'];
const usnmBowswa = usernames['bowswa'];
const usnmRamenator = usernames['ramenator'];
//extract encrypted passwords to indiv vars
const passwords = credsObj['passwords'];
const encPwdAult = passwords['ault'];
const encPwdBowswa = passwords['bowswa'];
const encPwdRamenator = passwords['ramenator'];
//extract decryption keys
const decryptionKey = credsObj['encryption']['cryptedKey'];
const secondLayerKey = credsObj['encryption']['keyCodeDecrypt'];
//decrypt passwords for storage
const pwdKey = CryptoJS.AES.decrypt(decryptionKey, secondLayerKey).toString(CryptoJS.enc.Utf8);
const pwdAult = CryptoJS.AES.decrypt(encPwdAult, pwdKey).toString(CryptoJS.enc.Utf8);
const pwdBowswa = CryptoJS.AES.decrypt(encPwdBowswa, pwdKey).toString(CryptoJS.enc.Utf8);
const pwdRamenator = CryptoJS.AES.decrypt(encPwdRamenator, pwdKey).toString(CryptoJS.enc.Utf8);
// --------------------------------------
// ---------- END AUTH PROCESS ----------
// --------------------------------------
//Check for enter key pushes
document.getElementById("usnm").addEventListener('keyup', (e) => {
if (e.key === 'Enter' || e.keyCode === 13) {
loader();
}
});
document.getElementById("pwd").addEventListener('keyup', (e) => {
if (e.key === 'Enter' || e.keyCode === 13) {
loader();
}
});
var timeout;
function loader(){
document.getElementById('login').style.display = 'none';
document.getElementById('loader').style.display = 'block';
timeout = setTimeout(login, 1000);
document.getElementById('uL').style.color = 'white';
document.getElementById('uL').innerHTML = 'Username';
document.getElementById('pL').style.color = 'white';
document.getElementById('pL').innerHTML = 'Password';
}
//onclick login, trigger function
function login(){
//get credentials
var username = document.getElementById("usnm").value;
var password = document.getElementById("pwd").value;
//determine user
if(username == usnmAult){
if(password == pwdAult){
userAult();
} else{
document.getElementById('pL').style.color = 'red';
document.getElementById('pL').innerHTML = '<b>Incorrect Password</b>';
}
} else if(username == usnmBowswa){
if(password == pwdBowswa){
userBowswa();
} else{
document.getElementById('pL').style.color = 'red';
document.getElementById('pL').innerHTML = '<b>Incorrect Password</b>';
}
} else if(username == usnmRamenator){
if(password == pwdRamenator){
userRamenator();
} else{
document.getElementById('pL').style.color = 'red';
document.getElementById('pL').innerHTML = '<b>Incorrect Password</b>';
}
} else{
document.getElementById('uL').style.color = 'red';
document.getElementById('uL').innerHTML = '<b>Incorrect User</b>';
document.getElementById('pL').style.color = 'red';
document.getElementById('pL').innerHTML = '<b>Incorrect Password</b>';
}
document.getElementById('login').style.display = 'block';
document.getElementById('loader').style.display = 'none';
}
//Triggers unlock procedures(Update welcome message, authenticate, display dashboard access)
function userAult(){
document.getElementById('loginBtn').style.display = 'none';
document.getElementById("welcomeUsername").innerHTML = "Hey Ault!";
postLogin();
userAuth = "ault";
}
function userBowswa(){
document.getElementById("welcomeUsername").innerHTML = "Hey Bowswa!";
postLogin();
userAuth = "bowswa";
}
function userRamenator(){
document.getElementById("welcomeUsername").innerHTML = "Hey Ramenator!";
postLogin();
userAuth = "ramenator";
}
function postLogin(){
//change attribute visibility
document.getElementById("continueButton").removeAttribute("hidden");
document.getElementById("loginForm").setAttribute("hidden", "true");
document.getElementById("adminOnly").setAttribute("hidden", "true");
document.getElementById("welcomeUsername").style.fontSize = "55px";
//check for enter key to trigger continue button
window.addEventListener('keyup', function(event) {
if (event.keyCode === 13) {
continueButton();
}
})
}
function continueButton(){
if(userAuth == "locked"){
window.alert("Authentication failed!");
} else{
window.location.href="/dashboard/dashboard.html";
}
}