Jump to content

Password Protect


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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...