-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlogin.js
More file actions
74 lines (71 loc) · 2.69 KB
/
login.js
File metadata and controls
74 lines (71 loc) · 2.69 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
var flag=0;
var trial=0;
var id,pass;
function login()
{
if(flag==1){
//checking password
if(document.getElementById('txt1').value=='')
{
return;
}
pass=document.getElementById('txt1').value;
var xmlReq=new XMLHttpRequest();
xmlReq.open("POST","http://moodshare.herokuapp.com/login",true);
xmlReq.setRequestHeader('Access-Control-Allow-Origin','*');
xmlReq.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlReq.send("username="+id+"&password="+pass);
xmlReq.onreadystatechange = function(){
if(xmlReq.readyState == 4 && xmlReq.status == 202){
window.open("success.html","_self");
return;
}
else if(xmlReq.readyState == 4 && xmlReq.status == 401){
trial++;
document.getElementById('txt1').type='text';
document.getElementById('txt1').placeholder='Enter ID';
document.getElementById('txt1').value='';
document.getElementById('logi').value="NEXT";
document.getElementById('Name').innerHTML=" ";
document.getElementById('NotYou').innerHTML=" ";
flag=0;
document.getElementById('oops').innerHTML="Oops, Username Or Password Was Wrong!";
if(trial==3)
{
//lock if tried more than 3 times
document.getElementById('txt1').disabled=true;
document.getElementById('logi').value="Too Many Tries";
document.getElementById('oops').innerHTML="Too Many Tries, Reload The Page";
flag=2;
return;
}
return;
}
};
}
if(flag==0)
{
//Entering id or username
if(document.getElementById('txt1').value==''){
return;
}
id=document.getElementById('txt1').value;
document.getElementById('logi').value="Sign in";
document.getElementById('Name').innerHTML='Welcome '+id;
document.getElementById('txt1').value='';
document.getElementById('txt1').type='password';
document.getElementById('txt1').placeholder='Password';
document.getElementById('oops').innerHTML=" ";
// If its not the username
document.getElementById('NotYou').innerHTML='   Not '+id+' ?';
flag=1;
return;
}
}
if(flag==2){
alert("Too Many Tries Reload The Page");
}
function notyou()
{
location.reload();
}