Click to See Complete Forum and Search --> : Multiuser Login and Password Script


bsmother
04-28-2006, 02:44 PM
Hello All,
I was hoping that someone could help me modify this script, you are probably very familar with it already.

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function LogIn(){
loggedin=false;
username="";
password="";
username=prompt("Username:","");
username=username.toLowerCase();
password=prompt("Password:","");
password=password.toLowerCase();
if (username=="guest" && password=="login") {
loggedin=true;
window.location="home-page.html";
}
if (username=="guest2" && password=="login2") {
loggedin=true;
window.location="home-page2.html";
}
if (loggedin==false) {
alert("Invalid login!");
}
}
// End -->
</SCRIPT>

<BODY>

<center>
<form><input type=button value="Login!" onClick="LogIn()"></form>
</center>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

I really like the sript and love the idea that mulitple users can be added, but I would like a few things to be done.

First I would like the password to be showed with * when typed in so when you are typing its not shown.

Second when you click on login, I would like it to open in a new window.

I know there is a way to do this, I figured it out back a few months ago but forgot how I did it, now its just a mess.

You could help it would be highly appreciated. Thank you!! :)
bsmother

A1ien51
04-28-2006, 03:42 PM
Basic hints for making it work:

1. Have to use form fields and not prompts

2. use window.open()

Eric

bsmother
04-28-2006, 06:10 PM
I am so sorry, I put the wrong script in. I am using a form based script. Here it is.

function Login(){
var done=0;
var username=document.login.username.value;
username=username.toLowerCase();
var password=document.login.password.value;
password=password.toLowerCase();
if (username=="member1" && password=="password1") { window.location="MembersArea/index.htm"; done=1; }
if (username=="member2" && password=="password2") { window.location="MembersArea/index.htm"; done=1; }
if (username=="member3" && password=="password3") { window.location="MembersArea/index.htm"; done=1; }
if (username=="member4" && password=="password3") { window.location="MembersArea/index.htm"; done=1; }
if (username=="member5" && password=="password3") { window.location="MembersArea/index.htm"; done=1; }
if (username=="member3" && password=="password3") { window.location="MembersArea/index.htm"; done=1; }
if (username=="member3" && password=="password3") { window.location="MembersArea/index.htm"; done=1; }
if (username=="member3" && password=="password3") { window.location="MembersArea/index.htm"; done=1; }
if (username=="member3" && password=="password3") { window.location="MembersArea/index.htm"; done=1; }

if (done==0) { alert("Invalid login!"); }
}
// End -->
</SCRIPT>

<form name=login>
<table width=225 border=1 cellpadding=3 background="fd2b.gif">
<tr><td colspan=2 align="center" background="fd2b.gif"><font size="+1"><b><img src="fd_lb3.gif" border="0">Members Area<img src="fd_lb3.gif" border="0"></b></font></td></tr>
<tr><td background="fd2b.gif">Username:</td><td background="fd2b.gif"><input type="text" name="username"></td></tr>
<tr><td background="fd2b.gif">Password:</td><td background="fd2b.gif"><input type="text" name="password"></td></tr>
<tr><td colspan=2 align="center" background="fd2b.gif"><input type="button" value="Login" onClick="Login()"></td></tr>
</table>
</form>
</div>

balloonbuffoon
04-28-2006, 06:58 PM
Problem one: change this:
<input type="text" name="password"> to this:<input type="password" name="password">Problem two: replace all instances of the following:window.location="MembersArea/index.htm";with this:window.open("MembersArea/index.htm",null);--Steve

bsmother
04-28-2006, 09:35 PM
Thank you so much Steve, I will go try that now!!

Thanks again for the help.
bsmother

balloonbuffoon
04-28-2006, 09:37 PM
No problem!

Good Luck,
--Steve

bsmother
04-28-2006, 11:54 PM
Thank you Steve, that worked.
The only problem I had was that I would get an login invaild message but the page would open in a new window anyway. I fixed it by using this:

if (username=="member2" && password=="password2") {window.open("MembersArea/index.htm"); done=1;}

Now it works prefect!!

Thank you so much; you were a HUGE help!
bsmother

balloonbuffoon
04-29-2006, 01:09 AM
No problem. Glad to see you got it working!

--Steve