-
Notifications
You must be signed in to change notification settings - Fork 1
/
register.js
executable file
·216 lines (194 loc) · 6.53 KB
/
register.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// JavaScript Document
function runReg()
{
$('#ajax-panel').empty();
$('#ajax-panel').html('<div class="loading"><b>Loading... </b><img src="/images/loading.gif" alt="Loading..." /></div>');
var _salt = "swagger";
var saltGet = $.ajax(
{
type: "GET",
url: "/getSalt.php",
data: "&d=y",
async:false,
success:
function(data)
{
_salt = data;
}
});
console.log("Salt: " + ">" + _salt + "<");
var formData = $('#regForm').serialize();
var password1 = formData.substring(formData.indexOf("password=", 0) + 9, formData.indexOf("password2=", 0) - 1);
var password2 = formData.substring(formData.indexOf("password2=", 0) + 10, formData.length);
console.log("P1: " + password1);
console.log("P2: " + password2);
var key = CryptoJS.PBKDF2("swag Swag", _salt, { keySize: 256/32, iterations: 500 });
var iv = CryptoJS.enc.Hex.parse('101112131415161718191a1b1c1d1e1f'); // just chosen for an example, usually random as well
var encP1 = CryptoJS.AES.encrypt(password1, key, { iv: iv });
var encP2 = CryptoJS.AES.encrypt(password2, key, { iv: iv });
var P1data_base64 = encP1.ciphertext.toString(CryptoJS.enc.Base64);
var P1iv_base64 = encP1.iv.toString(CryptoJS.enc.Base64);
var P1key_base64 = encP1.key.toString(CryptoJS.enc.Base64);
var P2data_base64 = encP2.ciphertext.toString(CryptoJS.enc.Base64);
var P2iv_base64 = encP2.iv.toString(CryptoJS.enc.Base64);
var P2key_base64 = encP2.key.toString(CryptoJS.enc.Base64);
console.log("P1 Data: " + ">" + P1data_base64 + "<");
console.log("P1 IV: " + ">" + P1iv_base64 + "<");
console.log("P1 Key: " + ">" + P1key_base64 + "<");
console.log("P2 Data: " + ">" + P2data_base64 + "<");
console.log("P2 IV: " + ">" + P2iv_base64 + "<");
console.log("P2 Key: " + ">" + P2key_base64 + "<");
/*var encP1 = CryptoJS.AES.encrypt(password1, _salt);
var encP2 = CryptoJS.AES.encrypt(password2, _salt);
var encP1Str = encP1.toString();
var encP2Str = encP2.toString();
console.log("Enc P1: " + ">" + encP1Str + "<");
console.log("Enc P2: " + ">" + encP2Str + "<");*/
/*var decryptedP1 = CryptoJS.AES.decrypt(encP1, _salt);
var decryptedP2 = CryptoJS.AES.decrypt(encP2, _salt);
var decStringP1 = decryptedP1.toString(CryptoJS.enc.Utf8);
var decStringP2 = decryptedP2.toString(CryptoJS.enc.Utf8);
console.log("Dec P1: " + decStringP1);
console.log("Dec P2: " + decStringP2);*/
/*var encrypted = CryptoJS.AES.encrypt("Message", _salt);
var decrypted = CryptoJS.AES.decrypt(encrypted, _salt);
var encString = encrypted.ciphertext.toString(CryptoJS.enc.Base64);
var decString = decrypted.toString(CryptoJS.enc.Utf8);
console.log("Enc string " + encString);
console.log("Dec string " + decString);
console.log("Form string " + formData);*/
var newFormData = $('#regForm').serializeArray();
/*newFormData[3].value = P1data_base64;
newFormData[4].value = P2data_base64;*/
newFormData.push({
name: "p1Enc",
value: P1data_base64
});
newFormData.push({
name: "p2Enc",
value: P2data_base64
});
newFormData.push({
name: "iv",
value: P1iv_base64
});
newFormData.push({
name: "k",
value: P1key_base64
});
newFormData = jQuery.param(newFormData);
console.log("Form string " + newFormData);
var request = $.ajax(
{
type: "POST",
url: "/register.php",
data: newFormData, //transmit encrypted passwords here
beforeSend:
function()
{
$('#ajax-panel').html('<div class="loading"><b>Loading... </b><img src="/images/loading.gif" alt="Loading..." /></div>');
},
success:
function(data)
{
var datToDisplay = "<b>ERROR: ";
var noWriteClose = false;
var success = false;
$('#ajax-panel').empty();
switch(data)
{
case "E1":
datToDisplay += "Invalid Username!";
break;
case "E2":
datToDisplay += "Invalid Email!";
break;
case "E3":
datToDisplay += "Invalid Year of Birth!";
break;
case "E4":
datToDisplay += "User already exists with given username or email!";
break;
case "E5":
datToDisplay += "Empty fields!";
break;
case "E6":
datToDisplay += "Username cannot contain a space!";
break;
case "E7":
datToDisplay += "Username too long! Limit 20 characters.";
break;
case "E8":
datToDisplay += "Email too long! Limit 50 characters.";
break;
case "E9":
datToDisplay += "Password too long! Limit 50 characters.";
break;
case "E10":
datToDisplay += "Username too short! Must be greater than 2 characters long.";
break;
case "E11":
datToDisplay += "Password too short! Must be greater than 5 characters long.";
break;
case "E12":
datToDisplay += "Passwords do not match!";
break;
case "E13":
datToDisplay += "Already Logged In! Please sign out before registering!";
break;
case "E14":
datToDisplay += "You did not validate the CAPTCHA!";
break;
case "F":
datToDisplay = "<b>Failed to write user.";
break;
case "S":
datToDisplay = "<b>Success! You will be redirected to the home page.</b>";
$('head').append('<meta http-equiv="refresh" content="3; url=http://www.vadweb.us/" />');
noWriteClose = true;
success = true;
break;
default:
datToDisplay += "GENERIC ERROR: " + data + "</b>";
noWriteClose = true;
break;
}
if (!noWriteClose)
datToDisplay += " Please try again.</b>";
$('#ajax-panel').html('' + datToDisplay);
},
error:
function()
{
$('#ajax-panel').html('<p class="error"><strong>Oops! Registration failed! Potential serious server issue.</strong> Try that again in a few moments. <br>If issues persist contact us.</p>');
}
});
return false;
}
/*
var request = $.ajax(
{
type: "GET",
url: "/getSalt.php",
data: "r=" + Math.random(),
beforeSend:
function()
{
// this is where we append a loading image
$('#ajax-panel').html('<div class="loading"><img src="/images/loading.gif" alt="Loading..." /></div>');
},
success:
function(data)
{
var salt = data;
console.log(salt);
$('#ajax-panel').empty();
$('#ajax-panel').html('<p class="success">' + salt + '</p>');
},
error:
function()
{
$('#ajax-panel').html('<p class="error"><strong>Oops! Registration failed!</strong> Try that again in a few moments.</p>');
}
});
*/