-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_password.js
More file actions
82 lines (73 loc) · 2.71 KB
/
change_password.js
File metadata and controls
82 lines (73 loc) · 2.71 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
function fetchResponse(response) {
if (!response.ok) return null;
return response.json();
}
function checkPwd(event){
check[0]=false;
const pwd = document.querySelector('#pwd').value;
console.log(pwd);
const c_speciali = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/;
if (!c_speciali.test(pwd)){
document.querySelector('#errore_pwd').textContent="La password deve contenere almeno un carattere speciale";
}
else{
if (pwd.length <= 8) {
document.querySelector('#errore_pwd').textContent="La password è troppo corta";
} else {
document.querySelector('#errore_pwd').textContent="";
check[0]=true;
}
}
}
function checkPwdV(event){
check[1]=false;
const pwd = document.querySelector('#pwd').value;
const pwd_v = document.querySelector('#pwd_v').value;
if(pwd===pwd_v){
document.querySelector('#errore_pwd_v').textContent="";
check[1]=true;
}
else
document.querySelector('#errore_pwd_v').textContent="Le password non corrispondono";
}
function onJSON(json){
if(json[0]){
alert('password modificata');
window.location = 'logout.php';
}
else{
alert('password non modificata, controllare la correttezza di tutti i campi');
}
}
function controllo(event){
event.preventDefault();
if(!check[0] || !check[1]){
alert("DEVI RISPETTARE LE RICHIESTE")
return;
}
const o=document.querySelector('#pwd_old').value;
const p=document.querySelector('#pwd').value;
const p_v=document.querySelector('#pwd_v').value;
if(o==="" || typeof o === 'undefined'){
document.querySelector('#errore_pwd_old').textContent="Inserire la vecchia password";
}
else{
if(typeof p === 'undefined' || p==="" ){
document.querySelector('#errore_pwd').textContent="Inserire la nuova password";
}
else{
if(typeof p_v === 'undefined' || p_v==="" ){
document.querySelector('#errore_pwd_v').textContent="Confermare la nuova password";
}
else{
const form_data={method: "post", body: new FormData(event.currentTarget) }
fetch("change_p.php", form_data).then(fetchResponse).then(onJSON);
}
}
}
}
let check=new Array(false, false)
document.querySelector('#pwd').addEventListener('blur', checkPwd);
document.querySelector('#pwd_v').addEventListener('blur', checkPwdV);
const form = document.querySelector('form');
form.addEventListener('submit', controllo);