1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
Internet_Security/public/js/main.js

79 lines
2.8 KiB
JavaScript

const main = document.querySelector("#main");
const resultMail = document.querySelector("#result_mail");
const passwordTest = document.querySelector("#password_test");
const resultPassword = document.querySelector("#result_password");
const passwordManage = document.querySelector("#password_manage");
const security2AF = document.querySelector("#security_2AF");
const cookie = document.querySelector("#cookie");
mailRegex = new RegExp("(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\\\[\x01-\x09\x0b\x0c\x0e-\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\\])");
document.querySelectorAll("input").forEach(el => {
el.addEventListener("change", (() => {
el.classList.remove("error");
}));
});
resultMail.querySelector("a").addEventListener("click", () => {
passwordTest.classList.remove("hide");
passwordTest.scrollIntoView({"behavior": "smooth"});
});
main.querySelector("#email").addEventListener("keyup", e => {
if (e.key === "Enter")
mailValid();
});
passwordTest.querySelector("#password").addEventListener("keyup", e => {
if (e.key === "Enter")
passwordCheck();
})
function mailValid() {
let input = main.querySelector("#email");
if (mailRegex.test(input.value)) {
resultMail.classList.remove("hide");
resultMail.scrollIntoView({"behavior": "smooth"});
} else {
input.classList.add("error");
}
}
function passwordCheck() {
let pass = passwordTest.querySelector("#password").value;
let secLevel = {
"length": false,
"uppercase": false,
"lowercase": false,
"number": false,
"special": false,
"identical": false,
"name": false,
"commonly": false
}
if (pass.length >= 8)
secLevel.length = true
if (pass.match("[A-Z]"))
secLevel.uppercase = true
if (pass.match("[a-z]"))
secLevel.lowercase = true
if (pass.match("[0-9]"))
secLevel.number = true
if (pass.match("\W"))
secLevel.special = true
if (pass.match)
secLevel.identical = true
if (pass.match)
secLevel.name= true
if (["123456", "password", "123456789", "12345678", "12345", "111111", "1234567", "sunshine", "qwerty", "iloveyou", "princess", "admin", "welcome", "666666", "abc123", "football", "123123", "monkey", "654321", "!@#$%^&*", "charlie", "aa123456", "donald", "password1", "qwerty123"].indexOf(pass) <= -1)
secLevel.commonly = true
resultPassword.classList.remove("hide");
resultPassword.scrollIntoView({"behavior": "smooth"});
}
function mailCheck(mail) {
}