Search
Recommended Sites
Related Links






   

Informative Articles

Advertising To Those With Javascript Turned Off
Just about all of the contextual advertising services and many other types of services use JavaScript to include their ads on your website. This is great because it's easy to put the code on your website, have ads running and then forget about...

An Easy Way To Include RSS In A Web Site
RSS has become a very important issue for web site promotion. This method helps to update web sites daily. A web site will always look actual. Why is RSS important? Visitors like always fresh content on a web site. A web site is...

Help your visitors zero in with Site-Flavored Google search
As Google has gained in their search reputation the past few years, many webmasters have added a Google search box to their pages. This is meant to provide a quick path for visitors to continue their search, should they not find what they're...

Popup Killers - Not just killing that Popup but also
With the increased use of popups on sites - when you enter, when you leave, while you are there - Popup killers (or stoppers) are all the rage. Companies use Popup killers as a marketing tool for frustrated webusers - they kill the Popup, the...

Sins of The Internet: Mousetraps (and worse)
One common unethical web technique is called mouse trapping, which is often used in conjunction with another highly immoral practice called page jacking. In it's simplest form, mouse trapping merely consists of redefining the back function so...

 
Javascript Password Protection


The protection of web pages using a password comes up earlier or later while developing your site. The most secure way is to implement PHP, ASP or other advanced web programming languages. In this tutorial you will find out how to protect pages using Javascript, because you may need to have a very simple protection, or your current hosting may not support PHP.

The first example we are going to discuss is the prompt() function. The function calls a small box to appear, and unless you enter correct password, you will not be able to view the page. The advantage is that you can't view the source code to find out the password without turning Javascript off. The code is as follows:









Now let's look at the code. When you enter the correct password, a box appears saying that Access is Granted, and the rest of the page is loaded. If the password is incorrect, you are redirected to denied.php. I used a little trick with the password here that can stop some unexperienced hackers ;)) the FAKEPASS is not the actual password, even though you can make it look like it. This is just a variable that is described in an external file - "prompt.gif". This is another trick - the external Javascript file has an extension .gif , which is used for images. The file however contains text, and the server will correctly treat it like a text file, not an image. So the content of prompt.gif is:



var FAKEPASS = "the_real_password";



As you see, here our variable is substituted with the word "the_real_password", which is the actual password.


The second option in protecting a page with Javascript is much prettier, and it actually allows you to have several login and password accounts. The code is:



Login



style="position:absolute;top:100;left:300;visibility:hidden;">


Entrance  

 Login:  

 Password:


 



Sign up for PayPal and start accepting credit card payments instantly.