-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewacct.js
56 lines (51 loc) · 1.48 KB
/
newacct.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
var socket = io();
var usr = document.getElementById("username");
var pwd = document.getElementById("password");
var cPwd = document.getElementById("confPassword");
var username = '';
var password = '';
hashCode = function(str){
var hash = 0;
if (str.length == 0) return hash;
for (i = 0; i < str.length; i++) {
char = str.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash;
}
return hash;
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function newAcct() {
if (usr.value.includes(" ")) {
document.getElementById("errors").innerHTML = "Error: Spaces are not allowed in the username!";
} else if (pwd.value == cPwd.value) {
username = usr.value;
password = hashCode(pwd.value);
socket.emit('new user', [username, password]);
} else {
document.getElementById("errors").innerHTML = "Error: Both passwords must match!";
}
}
socket.on('err', function(data){
document.getElementById("errors").innerHTML = data;
console.log('err : '+data);
pwd.value='';
cPwd.value='';
});
socket.on('a-ok', function(){
window.location.replace("/coms.html");
});