About Blogging WP Tutorials Google Apple Computers Downloads SEO Facebook Twitter
  • 22/02/2005    

Simple Scripts to Password Protect Your Webpage

Advertisements

You always wanted to password protect your webpages. Some web pages are best kept private. The javascripts below are simple ways to protect using a password your webpage.

WARNING :
As I said, these scripts are very simple javascript. They are the first line to protect privacy of webpages. Someone who can access the html page souce code can easily find the username and password and enter the page. The script will NOT work in Javascript disabled browsers or older browser versions not supporting javascript. So it is basically to stop routine surfers from accessing your pages. Anyone with a little idea about html and computers can see the source code. So if you have something IMPORTANT that you really want to password protect and not allow any access at all, DO NOT USE these and try alternative means.

Usage – Insert the code in between the HEAD tags of your webpage.

Password Protection Script 1

The javascript displays a form to enter the Username and Password. If either is wrong, it will display and alert screen like ‘Wrong Username’ or ‘Wrong Password’. The username is set to ‘secretname’ and the password is ‘secretpassword’ – both can be set as you like. If both are right, then you are taken to the next url, which is currently set to this blog.

<script language="javascript">
<!--// function pasuser(form) { if (form.id.value=="secretname") { if (form.pass.value=="secretpassword") { location="http://quickonlinetips.com/" } else { alert("Wrong Password") } } else { alert("Wrong Username") } } //-->
</script>
<form name="login">
Username: < input name="id" size="6" type="text">Password: < input name="pass" size="6" type="password">< input value="Login" onclick="pasuser(this.form)" type="button">
</form>

Password Protection Script 2

Insert this code in the ‘Head’ tags of the web page. When you enter the page, it will ask for a password, currently set to ‘secretpassword’. If the password is correct, you will be allowed to enter the page. Otherwise you can set it to redirect to any other page, currently it is set to this blog.

<SCRIPT language="JavaScript">
<!-- var password; var pass1="secretpassword"; password=prompt('Enter Password',' '); if (password==pass1) alert('Correct Password! Click OK to Enter!'); else { window.location="http://quickonlinetips.com/"; } //-->
</SCRIPT>

Insert these scripts into your html code for simple password protection of your pages. But remember the warning as mentioned before.

65 Responses

  1. i’m sorry but i still don’t get it. Can you please show me an example? Thanks alot

    shannon posted on 18/05/2006
  2. it only appears on top of the screen. help?

    zac posted on 23/05/2006
  3. I want to password block this because i have friends who want to gain access and i need help because words keep croping up and i can’t telll them to go away

    Sriram posted on 28/05/2006
  4. where should i put my script one?

    jason posted on 25/06/2006
  5. Insert the code between the HEAD tags. Otherwise it will not work and will display on the page.

    QuickOnlineTips posted on 25/06/2006

Leave a Reply to “Simple Scripts to Password Protect Your Webpage”

Name Email Site