-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfile_Management_check.js
134 lines (107 loc) · 2.98 KB
/
Profile_Management_check.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
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
function checker(password){
//Check if the pass is under 8 characters
if(password.length<8){
return false;
}
//I make the password into an array of characters
let character = password.split("");
let flag_1 = false;
let flag_2 = false;
let flag_3 = false;
for(var i=0;i<character.length;i++){
//Every character is matched with his ascii number
let asc_number = character[i].charCodeAt();
//Check if the character is a number
if(!isNaN(character[i]) === true){
flag_1 = true;
}
//Check if the character is a capital letter
if(character[i].match(/[A-Z]/)){
flag_3 = true;
}
//Check if the character is a special character
if((asc_number >=33 && asc_number <=47) || (asc_number >=58 && asc_number <=64) || (asc_number >=91 && asc_number <=96) || (asc_number >=123 && asc_number<=126)){
flag_2 = true;
}
//If the three flags are true then it passes the check we put it into
if(flag_1 == true && flag_2 ==true && flag_3 == true){
return true;
}
}
//If something fails it return false
return false;
}
function profile_manage(){
event.preventDefault();
let name = $("input[name=user_PM]").val();
let pass = $("input[name=pass_PM]").val();
let repeat_pass = $("input[name=repeat_pass_PM]").val();
let old_pass = $("input[name=old_pass]").val();
console.log(name);
console.log(pass);
console.log(repeat_pass);
console.log(old_pass);
if(pass !== repeat_pass){
Swal.fire({
text:"Passwords dont match!"
}).then(function(){
window.location.assign("Profile Management.php");
});
}else if(checker(pass) != true){
Swal.fire({
text:"Passwords must contain at least one number, one symbol, one capital letter and be more than 8 characters"
}).then(function(){
window.location.assign("Profile Management.php");
});
}else if(checker(pass) == true){
if(pass.match(/\s/)){
if(confirm("Do you want your password to have spaces?")){
const req = $.ajax({
url: "Profile_Management_backend.php",
type: "POST",
dataType: "script",
data: {username: name, password: pass,old_password:old_pass}
});
req.done(profile_changed);
event.preventDefault();
} else {
Swal.fire({
text:"Change of Password Failed!"
});
window.location.reload();
}
} else{
const req = $.ajax({
url: "Profile_Management_backend.php",
type: "POST",
dataType: "script",
data: {username: name, password: pass, old_password:old_pass}
});
req.done(profile_changed);
event.preventDefault();
}
}
}
function profile_changed(responseText){
if(responseText == 2){
Swal.fire({
text:"You typed wrong your old password"
}).then(function(){
window.location.assign("Profile Management.php");
});
}
else if(responseText == 3){
Swal.fire({
text:"This username is taked"
}).then(function(){
window.location.assign("Profile Management.php");
});
}
else{
Swal.fire({
text:"Successful Change of Information"
}).then(function(){
window.location.assign("index.php");
});
}
}