This is undoubtedly the best password protection JavaScript you'll ever find. Besides supporting multiple users, multiple passwords, and even multiple destination pages (after they successfully login), this script is presented in a very easy-to-use interface that you're sure to love!
Password:
<-- Must be exactly 8 characters
Page Name:
.html<-- Must be exactly 8 characters
Add the below code to the <body> section of your page:
<center> <tableborder=1>
<tr><formname=members><tdrowspan=4> <selectname=memlistsize=10onChange="showmem(this.form)"> <!-- Original: Dion -->
<!-- Web Site: http://www.iinet.net.au/~biab/ -->
<!-- Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! -->
<!-- "member name | password | destination pagename |" --> <optionselectedvalue="John
Smith|password|mainpage|">John
Smith <optionvalue="Peter
Jones|theirpwd|endpages|">Peter
Jones <optionvalue="Sue
Brown|asdfvcxz|nowheres|">Sue
Brown <optionvalue="Sally
West|zaqxswde|logintop|">Sally
West </select></td>
<td
align=right>User:</td><td><inputtype=hiddenvalue="0"name=entry>
<input
type=textname=memnamesize=8value=""></td></tr>
<tr><tdalign=right>Password:</td><td><inputtype=textname=passwordsize=8maxlength=8><fontsize="-1"><--Mustbeexactly8characters</font></td></tr>
<tr><tdalign=right>Page
Name:</td><td><inputtype=textname=pagenamesize=8maxlength=8><b>.html</b><fontsize="-1"><--Mustbeexactly8characters</font></td></tr>
<tr><tdcolspan=2align=center> <inputtype=buttonvalue="New
User"onclick="addnew(this.form);">
<input
type=buttonvalue="Delete
User"onclick="delthis(this.form);">
<input
type=buttonvalue="Update/Show
Coding"onclick="update(this.form);
create(this.form);"></td></tr>
<tr><tdcolspan=3align=center> <inputtype=textsize=60name=messagevalue="Note:
Password/Page Name must be exactly 8 letters! (a-z)">
<input
type=hiddenname=numvalue=1></td> </form></tr>
</table> <hrsize=2width=75%> <formname=js><textareacols=75rows=10name=scrptwrap=virtual> <scriptlanguage="javascript"type="text/javascript"> <!-- Begin var
params=newArray(4); var
alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI"; function
check(form){ which=form.memlist.selectedIndex; choice =form.memlist.options[which].value+"|"; if(choice=="x|"){ alert("Please
Select Your Name From The List"); return;
} p=0; for(i=0;i<3;i++){ a=choice.indexOf("|",p); params[i]=choice.substring(a,p); p=a+1;
} h1=makehash(form.pass.value,3); h2=makehash(form.pass.value,10)+"
"; if(h1!=params[1]){ alert("Incorrect
Password!");return;}; varpage=""; for(var
i=0;i<8;i++){ letter=params[2].substring(i,i+1) ul=letter.toUpperCase(); a=alpha.indexOf(ul,0); a-=(h2.substring(i,i+1)*1); if(a<0)
a+=26; page+=alpha.substring(a,a+1);}; top.location=page.toLowerCase()+".html";
} function
makehash(pw,mult){ pass=pw.toUpperCase(); hash=0; for(i=0;i<8;i++){ letter=pass.substring(i,i+1); c=alpha.indexOf(letter,0)+1; hash=hash*mult+c;
} return(hash);
} // End --> </script> </textarea>
</form> <scriptlanguage="javascript"type="text/javascript"> <!-- Begin var
params=newArray(4); var
script=document.js.scrpt.value; document.js.scrpt.value="Create
your users, their passwords, and their destination pages using the form
above.\n\nThen, click 'Show Coding' to see the login HTML and JavaScript
that you need to put on your page to password-protect your site with
that info.\n\nQuestions about this script or how to put it on your site
should be directed to it's author via email:
dion@mailhub.omen.com.au\n\n*Honestly, we don't even totally understand
this JavaScript!*"; var
alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI"; showmem(document.members); function
showmem(form){ document.members.num.value=document.members.memlist.length; varwhich=form.memlist.selectedIndex; splt(form.memlist[which].value); form.entry.value=which+1; for(i=2;i<5;i++){ form.elements[i].value=params[i-2];};
} function
splt(choice){ p=0; for(i=0;i<3;i++){ a=choice.indexOf("|",p); params[i]=choice.substring(a,p); p=a+1; }
} function
addnew(form){ newmem=getfields(form); var
who=prompt("New
User's Name:",""); form.memlist[form.memlist.length]=newOption(who,
newmem,false,true); if(navigator.appName=="Netscape"){ document.js.scrpt.value=script; history.go(0);
} else{ showmem(document.members); }
} function
getfields(form){ newmem=""; for(i=2;i<5;i++){ newmem+=form.elements[i].value+"|";}; for(i=3;i<5;i++){ a=form.elements[i]; for(k=0;k<8;k++){ }
} return(newmem);
} function
delthis(form){ if(confirm("Delete
"+form.memname.value+"?")){ form.memlist.options[form.entry.value-1]=null; form.message.value=form.memname.value+"
Deleted"; form.memlist.selectedIndex=0; if(navigator.appName=="Netscape"){ document.js.scrpt.value=script; history.go(0);
} else{ showmem(document.members); } }
} function
update(form){ msg="no"; a=form.elements[i]; for(k=0;k<8;k++){ b=a.value.substring(k,k+1); c=b.toUpperCase(); form.memlist[form.entry.value-1].value=getfields(form); form.message.value=form.memname.value+"'s
record was updated"; }
} function
create(form){