February 22nd, 2005
Simple Scripts to Password Protect Your Webpage
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.
Continue getting our new articles by RSS or email
Related articles
Password Protect Your Screensaver : Secure Your Computer
Security Alert! Stop Using These 10 Most Common Passwords
Yahoo! Sign-in Seal Fights Password Theft and Phishing
How to Fix Google Adsense Login Errors
Webpage Monitoring Services : Detects & Notifies Page Updates / Changes




Comments
RSS feed for comments on this post.1. Kya | 11/11/05 #
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 | 2/12/05 #
I just see the scripts (Both) printed in my blog instead of implemented. Why doesn’t it work?
3. hope this helps | 13/12/05 #
u have to remove the comments….so u remove the 2nd and the 2nd last line
4. Jade | 27/01/06 #
I did what you said and it still doesn’t work
5. Mark & Mandy | 28/01/06 #
works for me. nice post. simple, and stops the average person. i used the 2nd script.
thanks — mark
6. después | 2/02/06 #
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 | 8/02/06 #
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 | 25/02/06 #
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 | 12/03/06 #
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 | 12/03/06 #
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 | 18/05/06 #
i’m sorry but i still don’t get it. Can you please show me an example? Thanks alot
12. zac | 23/05/06 #
it only appears on top of the screen. help?
13. Sriram | 28/05/06 #
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 | 25/06/06 #
where should i put my script one?
15. QuickOnlineTips | 25/06/06 #
Insert the code between the HEAD tags. Otherwise it will not work and will display on the page.
16. f3l | 27/06/06 #
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 | 12/07/06 #
Can I add more than one username and password?
18. Porter | 24/07/06 #
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. Porter | 24/07/06 #
I couldn’t get any in-template tags to work, but I did get a password working by altering the body tag:
<body id=”body” onload=”var password=prompt(’pssst. What\’s the password?’,’ ‘);if (password!=’wtfrulookingat’) window.location=’http://www.google.com/’; else document.getElementById(’body’).style.visibility = ‘visible’;”>
Also, I added this to the styles in the <head>:
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.
20. blurrkidd | 11/08/06 #
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!!
21. fizz | 18/11/06 #
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!
22. milo | 22/11/06 #
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
23. QuickOnlineTips | 22/11/06 #
Do not forget to remove the “_” from the code provided. I have added that because the script cannot be posted in this post otherwise.
24. milo | 23/11/06 #
where is “in between the HEAD tags of your webpage”
25. Alex | 16/03/07 #
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.
26. justme | 12/04/07 #
I have tried BOTH scripts, modified without _ , and put right after Head tags, and they are not working!
27. sad | 10/11/07 #
just like justme. i have tried both scripts. deleted the _, put it between the head tags. yet, they’re not working! any clue?
28. QuickOnlineTips | 11/11/07 #
Now you do not need to remove _ as I have been able to post the code without it. Copy and paste the code as it is.
29. joanL | 12/11/07 #
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’?
30. joanL | 13/11/07 #
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??
31. turnip | 7/12/07 #
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?
32. wingyan | 5/01/08 #
hello. I’m using xanga, but I tried and it cannot really work. Can you reply to my email? thanks alot
33. greg | 10/01/08 #
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 .
34. greg | 10/01/08 #
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.
35. Sarah | 11/03/08 #
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!
36. dette | 14/04/08 #
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!
37. Pila | 5/07/08 #
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.
Comment on “Simple Scripts to Password Protect Your Webpage”