|
|
#1 (permalink) |
|
Banned
Join Date: Feb 2007
Location: Sydney
Age: 19
Posts: 4,205
Rep Power: 0
|
This seems the right place to ask :P
I'm making a JS login using an array, which locks the user out after 3 tries. It's for an assignment, and I wouldn't usually ask but for the life of me, I can't figure out why it still says "x incorrect login attempts" even when I get it right. Code:
var username = new Array();
username[0] = "Blake";
username[1] = "Morgan";
username[2] = "Steve";
username[3] = "Admin";
username[4] = "Adam";
var password = new Array();
password[0] = "pass1";
password[1] = "pass2";
password[2] = "pass3";
password[3] = "pass4";
password[4] = "pass5";
var logincheck = false;
var Number = 1;
function Login()
{
for (var i = 0; i < username.length; i = i + 1)
{
if ((username[i] == document.LForm.UName.value) && (password[i] == document.LForm.PWord.value))
{
window.location.href="members.htm";
logincheck = true;
}
}
{
if (!logincheck)
{
alert("Incorrect Username or Password combination.");
}
{
do {
alert(Number + " " + "incorrect login attempts.");
Number++;
}
while(Number < 1)
}
}
if (Number > 3)
{
document.location.href = 'blocked.htm'
}
}
|
|
|
|
|
|
|
|
#4 (permalink) |
|
Pro Member
Join Date: Jun 2006
Age: 19
Posts: 5,593
Rep Power: 8
|
You have a few stray brackets all over the place..
Code:
var username = new Array();
username[0] = "Blake";
username[1] = "Morgan";
username[2] = "Steve";
username[3] = "Admin";
username[4] = "Adam";
var password = new Array();
password[0] = "pass1";
password[1] = "pass2";
password[2] = "pass3";
password[3] = "pass4";
password[4] = "pass5";
var logincheck = false;
var Number = 1;
function Login()
{
for (var i = 0; i < username.length; i = i + 1)
{
if ((username[i] == document.LForm.UName.value) && (password[i] == document.LForm.PWord.value))
{
window.location.href="members.htm";
logincheck = true;
}
}
{ <---- that one
if (!logincheck)
{
alert("Incorrect Username or Password combination.");
}
{ <--- that one
do {
alert(Number + " " + "incorrect login attempts.");
Number++;
}
while(Number < 1)
} <------
} <---- this one and the above one
if (Number > 3)
{
document.location.href = 'blocked.htm'
}
}
What browser are you using? I'm fairly certain IE would throw errors with that script. chem
__________________
There are no stupid questions... but there are alot of inquisitive idiots. - |
|
|
|
|
|
#6 (permalink) |
|
Pro Member
Join Date: Jun 2006
Age: 19
Posts: 5,593
Rep Power: 8
|
Did that fix it? Having the brackets there stuff up the parsing completely.
(btw, i=i+1 looks so yuck.. try ++i or i++ )chem
__________________
There are no stupid questions... but there are alot of inquisitive idiots. - |
|
|
|
|
|
#8 (permalink) |
|
Pro Member
Join Date: Jun 2006
Age: 19
Posts: 5,593
Rep Power: 8
|
Can't read **** on these forums so I re-wrote it. On the third attempt it goes to blocked ..
Code:
var username = new Array();
username[0] = "Blake";
username[1] = "Morgan";
username[2] = "Steve";
username[3] = "Admin";
username[4] = "Adam";
var password = new Array();
password[0] = "pass1";
password[1] = "pass2";
password[2] = "pass3";
password[3] = "pass4";
password[4] = "pass5";
var wrong_attempts = 0;
var success = false;
function Login()
{
for (var i = 0; i < username.length; ++i)
{
if (wrong_attempts > 1)
window.location.href = "blocked.htm";
if ((username[i] == document.LForm.UName.value) && (password[i] == document.LForm.PWord.value)) {
success = true;
window.location.href = "members.htm";
break;
}
}
if (!success) {
alert('Incorrect Username or Password combination');
wrong_attempts++;
}
}
__________________
There are no stupid questions... but there are alot of inquisitive idiots. - Last edited by chemicalNova; 20-06-2007 at 04:35 PM.. Reason: ****ed the loop LOL |
|
|
|
|
|
#11 (permalink) | |
|
Contributing Member
Join Date: Jun 2006
Posts: 607
Rep Power: 3
|
Quote:
Case in point, if we want to set an event callback, setAttribute() the standard versus attachEvent() or obj.property = function() { ... } for ie.
__________________
92% of teens have moved on to rap. If you are part of the 8% who still listen to real music, copy and paste this into your signature. |
|
|
|
|
|
|
#12 (permalink) |
|
Contributing Member
Join Date: Jun 2006
Posts: 607
Rep Power: 3
|
Remember JS authentication is broken by definition ('client side'). And also, if you ever feel like making things neater, look at how we can form objects on the fly in js. For Example
var details = [ {username: 'jim', password: 'jimmy'}, {username: 'bob', password: 'bobby'} ] Will give us basically an array of username/password tuples (objects) so we could details[0].password // jim's password which means you could: for (var i in details) { if(details[i].username == ... } gl, hf!
__________________
92% of teens have moved on to rap. If you are part of the 8% who still listen to real music, copy and paste this into your signature. |
|
|
|



)


