Im doing a login page for an assessment and allowed to use online sources and open book. Iv made a login page making use of an array which is asked in my assignment but when it runs it accepts any password and username you enter. I need it to accept only what is in the array.
from what i have done i do not understand as to me it is logical …
Any help would be appreciated.
<html>
<script type="text/javascript">
function userLogin(user1,pass1)
{
var userName = user1.value;
var userPass = pass1.value;
var correct = 0; // set variable of correct so that if its turned ON ( True ) it runs the statement bellow.
var wrong = 1; // set variable of Wrong so that if wrong is switched false then it alerts the user.
var i = 0
var userarray = ["User1", "User2", "User3", "User4", "User5"]; // set usernames and passwords in the array.
var passarray = ["Pass1", "Pass2", "Pass3", "Pass4", "Pass5"];
for (var i=0; i < userarray.length; i++)
{
if (( userName == userarray[i]) && ( userPass == passarray[i])) // if variables userName and userPass are equals to the array then correct = true.
{
correct = 1;
}
}
if (correct = 1) // when correct is true this statement is run.
{
window.location="bookingPage.htm" // launches the bookings page.
wrong = 0;
}
else
{
alert ("Access Denied");
correct = 0;
}
}
</script>
<body>
<center>
<br />
<table border="1">
<tr>
<td colspan="2">
<center>
<h1><b>Login Area</b></h1>
</center>
</td>
</tr>
<tr>
<td>
<h1><b>Username</b></h1>
</td>
<td><form name="login">
<input name="user1" type="text"></td>
</tr>
<tr>
<td><h1><b>Password</b></h1></td>
<td><input name="pass1" type="password"></td>
</tr>
<tr>
<td>
<center>
<input type="button" value="Login" onClick="userLogin(user1,pass1)">
</center>
</td>
<td>
<center><br>
</td>
</tr>
</table>
</center>
</body>
</html>