mplutodh1
05-28-2003, 11:25 PM
I need help getting this script to work. Basically what it does:
onLoad - prompts the user for a username and password
- writes both of these to a cookie
The next time the page loads, rather than prompting the user for this information again, it checks the cookie, retreives the data previously entered and then has an alert box pop up that says "Welcome +username+"
If after 3 tries the user does not get the information correctly, it reverts back to the prompt for username and password.
Here is what I have so far, essentially I think I need an if statement that says if username and password equal whatever is in the cookie alert, else - repeat 2 more times, then go to the function called by the onLoad
<HTML>
<HEAD>
<TITLE>Login</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function LogIn(){
loggedin=false;
username="";
password="";
username=prompt("Username:","");
username=username.toLowerCase();
password=prompt("Password:","");
password=password.toLowerCase();
if (username=="+username+" && password=="+password+") {
loggedin=true;
window.location="home.html";
}
if (loggedin==false) {
alert("Invalid login, Please try again!");
}
}
// Stores UserName & Password in a Cookie
function setCookie() {
var expiresDate = new Date();
expiresDate.setFullYear( expiresDate.getFullYear() + 1 );
document.cookie = encodeURI("username=" + "name") + ("password=" + "password") + "expires = " +
expiresDate.toUTCString()};
// End -->
</SCRIPT>
</HEAD>
<BODY onLoad="LogIn()">
</BODY>
</HTML>
onLoad - prompts the user for a username and password
- writes both of these to a cookie
The next time the page loads, rather than prompting the user for this information again, it checks the cookie, retreives the data previously entered and then has an alert box pop up that says "Welcome +username+"
If after 3 tries the user does not get the information correctly, it reverts back to the prompt for username and password.
Here is what I have so far, essentially I think I need an if statement that says if username and password equal whatever is in the cookie alert, else - repeat 2 more times, then go to the function called by the onLoad
<HTML>
<HEAD>
<TITLE>Login</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function LogIn(){
loggedin=false;
username="";
password="";
username=prompt("Username:","");
username=username.toLowerCase();
password=prompt("Password:","");
password=password.toLowerCase();
if (username=="+username+" && password=="+password+") {
loggedin=true;
window.location="home.html";
}
if (loggedin==false) {
alert("Invalid login, Please try again!");
}
}
// Stores UserName & Password in a Cookie
function setCookie() {
var expiresDate = new Date();
expiresDate.setFullYear( expiresDate.getFullYear() + 1 );
document.cookie = encodeURI("username=" + "name") + ("password=" + "password") + "expires = " +
expiresDate.toUTCString()};
// End -->
</SCRIPT>
</HEAD>
<BODY onLoad="LogIn()">
</BODY>
</HTML>