954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Password Protect Your Web Page

0
By Hosmer23 on Apr 22nd, 2007 6:48 am

A handy code that brings up a password window to keep others off of the web pages you choose.

<script language="JavaScript">
var password;
var pass1="PASSWORD-HERE";
password=prompt('Whats The Magic Word?',' ');
if (password==pass1) alert('That Is Correct!');
else {
  window.location="SITE-LINK";
}
</script>

I'm really new to Javascript so please pardon this naive question - if the value of the password is posted in line 3 and anyone can view the source of a page, how is the password protected?

Thanks

Randy Epperson
Newbie Poster
3 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

You can make a new .js/.jse file and make variables containing the password. Still, you can get into it. Try to make it as secure as you can. But it wouldn't be worth it for just 1 web page...

Mohan0704
Newbie Poster
7 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

You can make a new .js/.jse file and make variables containing the password. Still, you can get into it. Try to make it as secure as you can. But it wouldn't be worth it for just 1 web page...

Mohan0704
Newbie Poster
7 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

sorry for the last post, my browser was laggy/not responding

Mohan0704
Newbie Poster
7 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

It does not work

auvi1
Newbie Poster
1 post since May 2009
Reputation Points: 10
Solved Threads: 0
 

Try encrypting the password...

DealthRune
Light Poster
45 posts since Apr 2009
Reputation Points: 12
Solved Threads: 0
 

Also, try this script

<html>
<head>
<script type="text/javascript">


var pass1='password';
var password=prompt("What's the magic word?","");
if (password==pass1)
  {
  document.write("Correct!");
  }else{
  document.write('Incorrect!')
  }

</script>
</head>
<body>

</body>
</html>
DealthRune
Light Poster
45 posts since Apr 2009
Reputation Points: 12
Solved Threads: 0
 

help me please i do not know javascript well; how would you do multiple passwords its for a project

jpdude11
Newbie Poster
1 post since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

hey ummm, can't you right click and "view source", read through and just get the password, or havee l missed the point?

dlannetts
Junior Poster in Training
84 posts since Jan 2010
Reputation Points: 10
Solved Threads: 4
 

I need help too , I yes dont one no one to see my page only people i one them too see it

Hanabusa
Newbie Poster
2 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

if you must use javascript, javascript security is a joke
hash the password, and only put the hash in your file
then hash the entered password and compare the hashes
it is more difficult to work an md5 or sha1 backwards to get the text

security is usually configured at the server
an ajax call to verify the password, or submitting the page for server verification is preferred to anything clientside

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

So easily got it now

Hanabusa
Newbie Poster
2 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Personally if you're using Apache I'd just use htpasswd with .htaccess

EvolutionFallen
Junior Poster
198 posts since Aug 2009
Reputation Points: 40
Solved Threads: 31
 

.htaccess .htpassword is less efficient than per user access control through settings stored in the database with the user details.
The reason why all access controlled sites use this method instead of .htpassword.
What we do personally, becomes irrelevant when the site is not personal, still use .htpassword to further lock admin-only folders, belt and braces approach

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

If I'm understanding you correctly, bob, I completely agree with you that htpasswd is less efficient with more users. However if you're going to store a single pw in the code why not use htpasswd instead?

EvolutionFallen
Junior Poster
198 posts since Aug 2009
Reputation Points: 40
Solved Threads: 31
 

So im using the code at the top of the page and it works great in every browser but internet explorer. It just auto redirects like you type the incorrect password in. Any help would be much appreciated.


I figured it out. I had to add it to a trusted list so that my computer trusted the site. I wonder if there is another work around on that.

NeakUp
Newbie Poster
1 post since May 2010
Reputation Points: 10
Solved Threads: 0
 

is there any way to embed the window in the page?

stjhess
Newbie Poster
1 post since May 2010
Reputation Points: 10
Solved Threads: 0
 

Can we use this code in any language , means is this code is compatible to other languages or not.

StephenHarry
Newbie Poster
3 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

You certainly can. That is as secure as having a guard snail on duty.

MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You