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!

Password protecting web pages?

Status
Not open for further replies.

markdmac

MIS
Dec 20, 2003
12,340
US
I found the following sample script code:

Code:
	<script type="text/javascript">
		var pw =prompt('Please Enter a Password to View Protected Content: ','');
 			if (pw != 'XYZ') top.location = 'index.html';</script>

I have a need to password protect some pages and would like to have support for both username and password. Tight security is not a real issue, we just want to use this to encourage people to register on the site.

Is there a way to edit the above sample so it will accept input for both a user name and a password?

Next step is I would like the user to only be prompted once for a group of pages. So I assume I require the use of a cookie.

I know how to do this easily with ASP code, but my customer is not using a Windows Web Server.

Many thanks for any assistance, JavaScript is not my area of expertise, vbscript is and the customers server prevents me from leveraging my vbscript knowledge.
 
Thanks again dwarfthrower. I made the suggested changes but the result remains the same. I just want to be sure I am using the right code on the page as well. I'm still using:

Code:
<script type="text/javascript"> 
if (!checkSession() || !passwordValidated())
  {
  window.top.location.href="login.html";
  } 
</script>

I have that code in the header section of the page.


I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Since passwordValidated() can't return false, you could removed that from the conditional.

Then, before checkSession() returns false, it's already changed the URL, so that part of the conditional won't do anything.

Under what conditions do you want your page to redirect to the login page?

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top