-
Notifications
You must be signed in to change notification settings - Fork 0
/
resetpassword.js
115 lines (109 loc) · 4.21 KB
/
resetpassword.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
let password = '';
let passwordConfirm = '';
let passwordValid = false;
let sending = false;
$(document).ready(function(){
// Lots of if statements for error checking
$('#passwordInput').on('input', function(){
passwordValid = false;
password = $('#passwordInput').val();
if(password)
{
if(password.length >= 6)
{
// Check for any of the following characters: [ ] ! * \ ( )
let invalidPasswordRegex = /[\[\]!\s*'\(\)]/;
if(!invalidPasswordRegex.test(password))
{
// Check for any non-alphanumeric character (aka any special character)
let alphanumericRegex = /^[A-Za-z0-9]*$/;
if(!alphanumericRegex.test(password) || password.length > 10)
{
$('#passwordMessage').html("Strong password")
$('#passwordMessage').attr('class', 'success');
}
else
{
$('#passwordMessage').html("Weak password")
$('#passwordMessage').attr('class', 'warning');
}
passwordValid = true;
}
else
{
$('#passwordMessage').html("Password cannot contain any spaces or any of the following characters: [ ] ! * \ ( )")
$('#passwordMessage').attr('class', 'error');
}
}
else
{
$('#passwordMessage').html('Password must be at least 6 characters long')
$('#passwordMessage').attr('class', 'error');
}
if(passwordValid && password === passwordConfirm)
{
$('#passwordConfirmMessage').html('Passwords match')
$('#passwordConfirmMessage').attr('class', 'success');
}
else if(passwordConfirm)
{
$('#passwordConfirmMessage').html('Passwords do not match')
$('#passwordConfirmMessage').attr('class', 'error');
}
else
{
$('#passwordConfirmMessage').html('<br/>')
}
}
else
{
$('#passwordMessage').html('Password cannot be empty')
$('#passwordMessage').attr('class', 'error');
}
})
$('#passwordConfirmInput').on('input', function(){
password = $('#passwordInput').val();
passwordConfirm = $('#passwordConfirmInput').val();
if(password && passwordValid && password === passwordConfirm)
{
$('#passwordConfirmMessage').html('Passwords match')
$('#passwordConfirmMessage').attr('class', 'success');
}
else if(passwordConfirm)
{
$('#passwordConfirmMessage').html('Passwords do not match')
$('#passwordConfirmMessage').attr('class', 'error');
}
else
{
$('#passwordConfirmMessage').html('<br/>')
}
})
$('#passwordResetForm').submit(function(){
let password = $('#passwordInput').val();
let passwordConfirm = $('#passwordConfirmInput').val();
let email = $('#email').val();
let token = $('#token').val();
let salt = $('#salt').val();
if(passwordValid && password === passwordConfirm && !sending)
{
sending = true;
$('#statusMessage').html("Loading...");
$('#statusMessage').attr('class', '');
// encodeURIComponent ensures special characters are processed properly
$.post("api/resetpassword.php", 'email=' + encodeURIComponent(email) + '&token=' + token + '&password=' + encodeURIComponent(password) + '&salt=' + salt, function(data){
if(data.status = "Success")
{
window.location.href = "login.php";
}
else
{
sending = false;
$('#statusMessage').html(data.status);
$('#statusMessage').attr('class', 'error');
}
})
}
return false;
})
})