Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple password protection using Javascript

Password Protection

Simple password protection using Javascript

by  liamm  Posted    (Edited  )
The following code creates a simple password login form. The password is the html name of the page you are linking to i.e. if you want to log into "membersonly.html" the password you use would be "membersonly". Of course you can use any text before the .html. This isn't the most secure password protection but it is useful where serious security isn't an issue

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
How to call the page:
On your call from page insert the following -
<script language="JavaScript">
<!--//BEGIN Script

function new_window(url) {link = window.open(url,"Link","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=350,height=200,left=350,top=300");}
//END Script-->

</script>

Suppose the log-in page is in your 'Members' directory,the hyperlink address would be:-

javascript:new_window('members/login.htm')

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The code for your log-in form would be:-


<html>

<head><script Language="JavaScript">
<!--
function password(){
top.opener.parent.window.location.href=document.passform.passtext.value + ".htm"
window.close();
}
//-->
</script>


<title>Members Log In</title>
</head>

<body BGCOLOR="#C0C0C0" topmargin="10" leftmargin="10">

<p align="center"><font face="Verdana" size="1">To continue, please enter your Members'
Password:</font></p>

<form name="passform">
<div align="center"><center><table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><font face="Verdana" size="1">Password:á </font></td>
<td><font face="Verdana" size="1"><input type="password" name="passtext" size="20"></font></td>
</tr>
</table>
</center></div><div align="center"><center><p><font face="Verdana" size="1"><input
type="button" value=" Enter " onClick="password()"
style="font-family: sans-serif; font-size: 8pt"></font></p>
</center></div>
</form>
</body>
</html>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The page you are linking to needs to be in the same directory as your log-in page. Therefore multiple passwords can be used to log in to different pages. For example your log-in page is in the 'Members' directory. Also in the 'Members' directory are the pages admin.html and guest.html. You now have 2 password options for the other pages in your 'Members' directory, admin and guest.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top