Simple Scripts to Password Protect Webpages

Here are some simple password protection scripts to password protect webpages. Some web pages are best kept private. The javascripts below are simple ways to protect using a password your webpage.

LIMITATIONS

password protection scripts

  • 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 source code can easily find the username and password and enter the page. Anyone with a little idea about html and computers can see the source code.
  • 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.

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 html  tags of your webpage. Remember to replace our url ‘quickonlinetips.com’ with the url 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.

62 comments on “Simple Scripts to Password Protect Webpages

  1. Kya says:

    Any idea why I can’t get any of those scripts to work on my blog??? Could it be blogger blocking it? Please help!!! THANK YOU!

  2. CrAz1iA957 says:

    I just see the scripts (Both) printed in my blog instead of implemented. Why doesn’t it work?

  3. hope this helps says:

    u have to remove the comments….so u remove the 2nd and the 2nd last line

  4. Jade says:

    I did what you said and it still doesn’t work

  5. Mark & Mandy says:

    works for me. nice post. simple, and stops the average person. i used the 2nd script.
    thanks — mark

  6. despus says:

    I’ve been thinking… (I don’t know the Java language) how about using some one-way coding algorithm, so it could be more secure (the page storing the encoded form of the pw). something like this

  7. Anonymous says:

    Works for me too. Thanks for the script. I have one question though. I noticed that the password prompt only appears when I type my Blogspot address exactly as it’s shown to me when I log in and go under Settings and then Publishing (ie. without the ‘World Wide Web’ part of the address). Is there a way to get the prompt to show up even with different variations of my address? By typing in my address starting with ‘www’, people can still access my blog without the password. Thanks in advance. I’m not very computer savvy. Any help would be appreciated.

  8. Anonymous says:

    I just have a basic blogger blog – do I enter the codes into the ‘Template’ section? If so, where in the Template html do I enter it? I’ve tried to enter it into the ‘head’ section and the password isn’t coming up…

    Thanks for your help!

  9. Jess says:

    Hi;

    I’m really keen to use these scripts, I’ve tried both html codes but I can’t seem to get the passwords to work. I would be really grateful. I’m mostly just getting the text appear at the top of my blog. Thanks heaps – awesome website!

  10. Quick Online Tips says:

    Please see that the all code inbetween the script tags of the code is inserted between the HEAD tags of your page. Maybe that is why the text is showing on your blog.

  11. shannon says:

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

  12. zac says:

    it only appears on top of the screen. help?

  13. Sriram says:

    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

  14. jason says:

    where should i put my script one?

  15. QuickOnlineTips says:

    Insert the code between the HEAD tags. Otherwise it will not work and will display on the page.

  16. f3l says:

    if someone has javasript disabled, and hits “view source”, he can see the url pointed to, and later continue into the “secret data” with litle or no effort (he can see the pass too, since it’s in clear text, inside the page).

    this is no substitute for a decent ldap, or server side security system, shich is a must when data is really private.

    also if you want your data be even safer, you mst use SSL for the transmisison as well.

    let’s just hope this doesn’t get used wide spread.

    just in case you WANT to use this script, just make shure you dont make the password “null”

  17. Henry says:

    Can I add more than one username and password?

  18. Porter says:

    I couldn’t get any in-template tags to work, but I did get a password working by altering the tag:

    Also, I added this to the styles in the :

    body {visibility:hidden}

    This way, when the page loads, all my blog content is hidden, so if they get redirected they never see anything, but if the password is correct, the body is set to be visible.

  19. blurrkidd says:

    I just cant get it to work..it become text on the top..and then my blog will come out..I need help..I dont understand!!

  20. fizz says:

    thanks, been looking for a simple password protect that you can put on the page itself. works like a charm.

    for the second script, you need to take out the , as well as _ before both SCRIPTs.

    in BlogSpot, yeah, put it between the head tags in the Edit HTML part.

    sure, any decently experienced person can hit view source, and anyone using Opera can just check the ‘disable javascript’ checkbox on the prompt, but it keeps out the masses.

    thanks!

  21. milo says:

    i tried using de java scrpiy, but it does not seem to work,
    it jus keep appearin at de top of de blog..
    plz help on where to put..
    thanks

  22. milo says:

    where is “in between the HEAD tags of your webpage”

  23. Alex says:

    When you say insert it between the head tags, where are these head tags? I don’t know which ones they are, can you make a screen shot possibly? Defining the exact location of where to input the HTML? Thank you.

  24. justme says:

    I have tried BOTH scripts, modified without _ , and put right after Head tags, and they are not working!

  25. sad says:

    just like justme. i have tried both scripts. deleted the _, put it between the head tags. yet, they’re not working! any clue?

  26. joanL says:

    I have used the second version and it is working fine – thanks. The only thing I am struggling with is that unless you enter the correct password it is impossible to get back onto the website without without having to close and re-open the browser. In case any genuine users have forgotten the password and want to come back to the password-protected area later but surf the rest of the website in the meantime, can you provide code for an additional message such as ‘you have entered an incorrect password, please re-enter here or continue to browse the website here’?

  27. joanL says:

    SORRY please ignore above comment as I have worked out what was going wrong. However, is there any way the password can appear as asterisks when people type it??

  28. turnip says:

    hi i’ve a problem i inserted the second script on my blogger account in between the head tags as it is. but it still doesn’t show up. any clue what to do?

  29. wingyan says:

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

  30. 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 .

Leave a Reply

Your email address will not be published. Required fields are marked *

All comments moderated. Use True name. No irrelevant links. Post useful content.