doomseason
12-11-2002, 12:43 PM
hi... i need to know how to make a page password protected. i need to be able to type in a password and have it go to a certain page if verified... and to another page if not verified... there is no user name... and no mulitple passwords... just one password. anyway... any help would be great... i'm fairly new to this stuff. THANKS!!!
<SCRIPT LANGUAGE="JavaScript">
<!--hide from older browsers
var password;
var pass="admin";
password=prompt('Please enter your password','');
if (password==pass)
{
window.location="page.htm";
}
else
{
window.location="somother.htm";
}
//End comment to hide script-->
</SCRIPT>
Is a simple way to add a password to you site. This is however, highly unsecure, and can only be used for a VERY minimal level of protection. Visitors would simply have to turn of JavaScript to enter you site. Also, anyone could view your sorce and find out the password. If you want a (slightly) more secure script, try looking through the scripts found here http://javascript.internet.com/passwords/ Note: No JavaScript password is even close to secure. I would use a CGI script or modify the .htaccess and .htpassword files on your server.
warbishop
12-11-2002, 08:41 PM
this might be of some help, of course i didnt write it. Got it from a guide(idiots guide) but its not too shabby. Not top notch but gives you decent security.
step 1:
place this code/tag somewhere within the body of the page you want the link at:
<A HREF="javascript:GetPassword()">link</A>
step 2:
on that same page, between the </HEAD> tag and the <BODY> tag put this code:
<SCRIPT LANGUAGE="JavaScript">
<!--
function GetPassword() {
window.open("jspass.htm", "","width=225,height=50")
}
//-->
</SCRIPT>
step 3:
now, when someone hits the "link" tag in step one, you'll be sent to the next HTML page. This is the entire page you will create exactly as I write it below and call it "jspass.htm". This is a password page, kinda a between page in my mind. This page will ask for a password. Basically the password will be the name of the page you want to goto. Since only you and the people with the name of the page can input it and goto that page, it works nicely. No password is ever contained in the script for someone to get. The name of whatever page you want to goto is the password. Get it? Here is the jpass.htm page exactly as it should be(NOTE: you will notice within this code the ext. of the target page is considered to end in .htm, but you can change this to .html if you like):
<HTML>
<HEAD>
<TITLE>Password Required</TITLE>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function SubmitPassword(frm)
{
//
// Get the value entered into the text box
//
var password = frm.pw.value
//
// Convert it to lowercase
//
password = password.toLowerCase()
//
// Add the .htm extension
//
var loc = password + ".htm"
//
// Make sure the user entered something
//
if (password != "")
{
//
// If so, send the browser there
//
opener.location.href = loc
}
//
// Close this window
//
window.close()
}
//-->
</SCRIPT>
<BODY BGCOLOR="#CCCCCC">
<FORM>
This page requires a password:<BR>
<INPUT TYPE="TEXT" NAME="pw" SIZE=15>
<INPUT TYPE="BUTTON" VALUE="OK"
onClick="SubmitPassword(this.form)">
</FORM>
</BODY>
</HTML>
step 4:
just make a target page, and wahtever its name can be your password.
Now, this isnt 100% perfect but does, to me, create a reasonable amount of security. You might want to put a "noindex, nofollow" meta tag on the target page also to protect it from getting crawled.
I know this isn't much, but its a start to my "giving back" for some of the help I've gotten. Good luck!
warbishop