Quick Online Tips
Home     About     Popular     Photoblog     Themes     Advertise     Shop     Jobs     Contact

Simple Scripts to Password Protect Your Webpage

February 22nd, 2005
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.

RSS Subscribe RSS feed     Bookmark and Share



57 Responses to “Simple Scripts to Password Protect Your Webpage”

  1. wingyan says:

    hello. I’m using xanga, but I tried and it cannot really work. Can you reply to my email? thanks alot

  2. greg says:

    Erm a little help here.. im currently using blogspot.. im not exactly tech savvy.. so could someone please detail alittle where im supposed to put in the html for this? i’ve tried in between the and .

  3. greg says:

    Erm a little help here.. im currently using blogspot.. im not exactly tech savvy.. so could someone please detail alittle where im supposed to put in the html for this? i’ve tried in between the and .

    thanks in advance.

  4. Sarah says:

    Just to be clear, the scripts above will work on a basic blogspot.com account? Meaning that if we send the URL to family/friends it will prompt them for a password before they are able to view the contents of the blog? Thank you!

  5. dette says:

    Hello! I have inserted the 2nd script as well in between the head tags, but when I view my site, the password prompt does not come up at all.

    Help? I’m also using this for a Blogger blog.

    Thanks – I’ve been searching online for a script like this, and yours is BY FAR the simplest one. :)

    Looking forward to hearing back from you!

  6. Pila says:

    Give nosle a shot. http://nosle.com

    You can protect any webpage or blog by adding 3 lines of code. No programming experience is required. It also provides a management console on its site where you can control access for your users. Javascript is required, which is the case for 99.99% of all websites today.

  7. clarice says:

    Hello. Nosle doesn’t work for me, I think it’s so difficult to understand and navigate through that site.
    With regards to this post, I have tried BOTH codes and pasted them both as they are and they have not worked. All I get are some of the html coding appearing at the top of my page.
    Is there anyone out there who can help me, please?

    Thanks in advance.

  8. Anonymous says:

    You can try filling in the gap between the “<” and the “input name” so it looks like this; Username:Password:. Hope it helps!

  9. Hi says:

    Try this code. Username:Password:. It worked for me. I hope this helps!

  10. Hi says:

    Username:Password:. This code works!

  11. Hi says:

    Ok, every time I click Login, it says error on page.
    HELP!

  12. Hello,

    I love the idea of your scripting here – it’s exactly what I’ve been searching for for weeks! I needed something simple to grant access to client account pages…nothing crazy. The only problem is I tried the second code – nothing happened. So I tried the first one and all it shows is the info I want to password protect along with this at the top:

    Username: Password:

    Please help!

    Thanks in advance!
    Kate

  13. To make this clearer – nothing shows up on the page except for the last half of the code:

    Username: Password:

    Thanks

  14. Alex says:

    I use this code to protect my Blogger blog:

    var p=confirm("website is password protected do you wish to enter?")
    if(p){
    var ans="your secret password goes here"
    var pass=prompt("Please enter password")
    if(pass!==ans)
    {
    alert("wrong password ")
    window.location="http://yahoo.com"
    }else{alert("you may enter");}
    }else{window.location="http://www.your website.com/"}

    I insert this code after .

  15. Rose says:

    Hi! Thanks for this blog entry. I’m using the second code with blogger, but it’s making me enter the password even when I’m editing the page. Do you know what’s wrong?

  16. Janice says:

    Hey, i tried everything. I tried the username:password:. thing & it still doesn’t work. Could you please post up step by step plus screenshots. Thanks ;D

  17. Manik says:

    Hey guys just to tell you if you use this script anyone can get in no matter what password or username you use because if you view the page source you can see everything….I don’t want to be rude to the person you made this script, but I felt like warning you..

  18. Phoebe says:

    hey, I can’t seem to get the code to work.
    I tried both,
    I put it in between the HEAD area,
    but it doesn’t show
    Does it have anything to do with the fact that my HEAD area stretches all the way to the end of my blogskin’s HTML code?
    please reply by email and not by here.
    Thank you. (=

  19. Fledermaus says:

    RE: Comment by Manik | 6/10/08 #

    As was stated,
    “Hey guys just to tell you if you use this script anyone can get in no matter what password or username you use because if you view the page source you can see everything….I don’t want to be rude to the person you made this script, but I felt like warning you..”

    The above should be a REAL concern to all and not to be disregarded. I know, most web crawlers don’t know about the Page Source routine, but all it takes is for someone “in the know” to tell someone who’s “ignorant” of it and your password is broken.

    I hope you have better suggestions for password protection, like maybe a scrambling technique or something else.

    /\/(°w°)\/\

  20. Shads says:

    Hi guys – I have it working.

    Open your web page in a TEXT EDITOR. Within the first few lines there should be a line

    html

    (in triangular brackets) and then

    head

    (also in triangular brackets) and after a bit

    /head

    (and again) In between the lines containing and paste all of script 2, and DELETE the Triangular Bracket Exclamation Mark — from the 2nd line and the — Triangular Bracket from the 6th line. To change the website you go to if you get the wrong password, change http://quickonlinetips.com/ to what you want. To change the password, change secretpassword too what you want.

    This is not a secure password, but works for sites that you would prefer to be private, e.g. space for family/friends etc.

  21. Anonymous says:

    Does this only work on html editors like Dreamweaver or free website editors too?

  22. Ken says:

    I got the first one working – many thanks.

    • Dominic says:

      I cant seem to get any of the 2 codes working with my Blog this is the error that appears
      Please correct the error below, and submit your template again.
      Your template could not be parsed as it is not well-formed. Please make sure all XML elements are closed properly.
      XML error message: The content of elements must consist of well-formed character data or markup.

      Anyone got any ideas

  23. Kymberly says:

    I know how to paste it in – that’s fine.

    I’ve followed every tip or trick here. No dice.

    It simply does not work. I have the nice little code in between the tags and all but it simply doesn’t have any effect. I just need something simple so I can break up with Typepad and go to Blogspot without the extended family giving me a hard time. They feel better with a “password entry” blog.

  24. Gangster29 says:

    Many health insurance plans ask patients to get a second opinion before they have certain operations that are not for an emergency. ,

Leave a Reply

  • Subscribe free daily email newsletter Why?
  • RSS   Feed readers   Add to Google Reader or Homepage   Twitter
writeWrite a guest article - Showcase your site to our active community of bloggers, technology experts, and geeks. Now read 100+ guest articles
Jobs
Jobs on SEO | Blogging | SEM | Marketing | Software | More...
Jobs in Google | Yahoo | Microsoft | Adobe | Ebay | Cisco | Intel
Post a job - only $50 for 30 days! | 8 more reasons

Must Buy Software