-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
86 lines (65 loc) · 2.57 KB
/
script.js
File metadata and controls
86 lines (65 loc) · 2.57 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
let email = document.getElementById("email");
let password = document.getElementById("password");
// ------------------------------------------------------------------------------------------------
let brogrammerz = JSON.parse(localStorage.getItem("brogrammerz")) || [];
// ------------------------------------------------------------------------------------------------
function login() {
if ((check_validation()) && (check_login_data())) {
email.value = "";
password.value = "";
alert("Welcome To Brogrammerz!");
location = "Profile.html";
}
if (email.value == "admin@gmail.com" && password.value == "hitart") {
alert("ADMIN LOGIN!");
localStorage.setItem("admin", "true");
location = "Admin.html";
}
};
// ------------------------------------------------------------------------------------------------
function check_validation() {
let email_pattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
let password_pattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,64}$/;
let email_validation = email_pattern.test(email.value);
let password_validation = password_pattern.test(password.value);
if (email.value == "") {
alert("Please Enter Your E-Mail!");
return false;
}
else if (!email_validation) {
alert("E-Mail Is Not Valid!");
return false;
}
if (password.value == "") {
alert("Please Enter Your Password!");
return false;
}
else if (password.value == "hitart") {
return false;
}
else if (!password_validation) {
alert("Password Is Not Valid!");
return false;
}
return true;
};
// ------------------------------------------------------------------------------------------------
function check_login_data() {
let filter_user = brogrammerz.filter((filter_user) => {
return filter_user.email == email.value;
});
let exist_user = filter_user[0];
if (!exist_user) {
alert("User Not Found! Please Register First!");
location = "Registration-Page.html";
return false;
}
else if ((email.value == exist_user.email) && (password.value != exist_user.password)) {
alert('Password Is Not Correct!');
return false;
}
else if ((email.value == exist_user.email) && (password.value == exist_user.password)) {
localStorage.setItem("logged-in-user-email", JSON.stringify(email.value));
return true;
}
};