16 enero 2010

You have created your first website but your page counter is not counting as fast as you thought it would. The only people who visit seem to be your mom and your best friend. Mothers understand but how do you explain this phenomena to your friend. It's simple really. Just password protect your site. Although this won't increase the number of visitors, you can use it explain why the numbers are not in the millions.

My first attempt at password protecting went something like this: Replace the page you want to protect with another page that would ask the visitor for a username and password. When the visitor clicks submit, the Javascript code on the page checks whether the username and password match and redirect the visitor to the original page.The code is given below.


Username:

Password:






Here is the actual form
Username:
Password:

It's pretty stright forward and it works. The only problem is that anyone can do a View|Source and find out your username and password and also the address of the password protected page, and that obviously is not good.

What we need is a method in which looking at the HTML source will reveal nothing about the username, password or the target page. One such method that is commonly used is to generate the target page name from what the user enters in the username and password fields and redirect the browser to that page. Take a look at the modified verifyLogin() function.





All that the function now does is to concatenate the username, the password and ".html" and redirect the browser to that location. So if your visitor entered secret as the username and page as the password, he/she would be taken to secretpage.html. If on the other hand, they don't know the correct username and password and entered say foo as the username and bar as the password, they would be redirected to the non-existant foobar.html and get an error saying that the page was not found.

There is another reason for wanting to password protect your pages other than the one mentiond at the beginning of this page, and that is you actually have something that you don't want to make public. My advice to you is do not use Javascript based password protection schemes.

See Also:
Password Protection Scripts from The Javascript Source
More Password Protection Scripts from WebAbstraction



© Copyright 2003-2004 Rajesh Vijayakumar Advertise | Privacy Policy | Link to us

Etiquetas: