Jump to content

Password Protect


...678

Recommended Posts

I wanted to password protect a few of my pages too, and although everyone told me it's better to do it with php, I did it with javascript. It's secure enough for me considering the info behind the password protection script isn't sensitive stuff:Here's the javascript code:
function protect(form) { if (document.passform.password.value == "password here") {  alert("Password correct, forwarding...");  document.location.href="members.html"; } else {  alert("Password Incorrect"); }

The document.passform.password.value would be the <input type="text"> field on the form (in this case the form is named "passform")Here's the form:

<form name="passform"> Password: <input type="password" name="password" /> <BR> <input type="submit" value="Submit" onClick="protect(form)"></form>

So that's it. Useful if you're not protecting any sensitive stuff (credit card details and such).

okbut where do i put the
function protect(form) {if (document.passform.password.value == "password here") {  alert("Password correct, forwarding...");  document.location.href="members.html";} else {  alert("Password Incorrect");}

Im not really sure what im doing.

Link to comment
Share on other sites

If you need a prompt to come up when the page loads and ask for password and redirect....

<html><HEAD><script language="JavaScript">var password;var pass1="cool";password=prompt('Please enter your password to view this page!',' ');if (password==pass1) {  alert('Password Correct! Click OK to enter!');  window.location.href="correctpage.htm"}else{ window.location="errorpage.htm";}</SCRIPT></HEAD>	<body>	</body></html>

Link to comment
Share on other sites

If you need a prompt to come up when the page loads and ask for password and redirect....
<html><HEAD><script language="JavaScript">var password;var pass1="cool";password=prompt('Please enter your password to view this page!',' ');if (password==pass1) {  alert('Password Correct! Click OK to enter!');  window.location.href="correctpage.htm"}else{ window.location="errorpage.htm";}</SCRIPT></HEAD>	<body>	</body></html>

THANK YOU!THATS EXACTLY WHAT I WANTED!!!!!!!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...