• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

simple password protect for web page?

I have a web page I want to require a password to get to.

What is the simplest way I can do this?

0
Tom Knowlton
Asked:
Tom Knowlton
1 Solution
 
Tom KnowltonWeb developerAuthor Commented:
I am fine with a JavaScript solution.
0
 
superslamwichCommented:
<script>
<!--
  ans = prompt('What is the password??')
  if(ans=='opensesame') {
  }
  else  {
    self.location='wrongpassword.html'
  }
//-->
</script>
0
 
superslamwichCommented:
change opensesame to whatever the password should be.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Tom KnowltonWeb developerAuthor Commented:
If I put your code into its own .js file...how do I call the function from my html code?
0
 
superslamwichCommented:
A few other notes:

-- Javascript passwords WILL NOT protect your page against people who want to get in.  If they really want to get the information, they can get past it by disabling javascript on their computer.

-- the password will be case-sensitive, so if a user types OpEnSeSaMe it will not count as the correct password.
0
 
superslamwichCommented:
<script language='javascript' src='thejs.js'>
</script>

should do the job
0
 
superslamwichCommented:
thejs.js is whatever your javascript file is named
0
 
Tom KnowltonWeb developerAuthor Commented:
<script language='javascript' src='thejs.js'>
</script>


I understand this, but how do I call the function inside  the thejs.js file?
0
 
Tom KnowltonWeb developerAuthor Commented:
If JavaScript is not secure, what would you recommend?

0
 
superslamwichCommented:
you would need to use a server-side script such as CGI or ASP.  My knowledge on these languages is very limited (just about nothing), but there are other people who would know.  

Depending on where your site is hosted, the proper code for a password protected page may be provided for free.

Also, if it's not very important information, a javascript password should work because people won't bother going to the trouble of disabling javascript to get a look at the page.
0
 
Tom KnowltonWeb developerAuthor Commented:
Understood.

Oh...and how do I call the JavaScript function from HTML after I have referenced the JS file?
0
 
Tom KnowltonWeb developerAuthor Commented:
My web page is hosted on Geocities which does not allow CGI scripts for free web pages (which mine is).

How do I call my JavaScript function from the HTML code?
0
 
Tom KnowltonWeb developerAuthor Commented:
Here is my HTML code:

I call function groupmemvalid() which does in fact prompt me for a password, but it does not prevent the page from loading anyway...you can see the page behind the password prompt!!!


<html>
<title>Capstone - Business Ethics</title>

<script src="pw.js" type="text/javascript"></script>

<body onload=groupmemvalid()>

...
...
...

</body>
</html>



Here is the javascript function:

function groupmemvalid() {
  ans = prompt('What is the password??')
 if(ans=='iraq') {
 }
 else  {
   alert("Wrong password.  Send e-mail to tom@thebuyersfund.com")
 }
}
0
 
cubrovicCommented:
There is a better solution to protect your page with simple javascript.

If you are using techunique above everyone can open your source code and see the password and your page is open.


But there is  a little trick to do better

Let say that you want to have a password for the page

midnight

You create a folder named "midnight" on your geocities account file manager.
Then you put the page (or pages) you want to protect in it.
(protected-page.html)

now in your notprotected html you can simply make link like this

<html>
<head>
<title>Somepagename</title>
<script language=JavaScript type=text/javascript>
<!--
function goTo(fn) {
window.location.href = prompt("enter password")+"\/"+fn
}

//-->
</script>
</head>
<body>
<a href="javascript:goTo('protected-page.html')">Link</a>
</body>
</html>


It's hard to break
simple and secure
0
 
Tom KnowltonWeb developerAuthor Commented:
I like this solution a lot.  Not bullet-proof, but a little more secure.

Thank you everyone.
0
 
Tom KnowltonWeb developerAuthor Commented:
For more points see this question:

http://www.experts-exchange.com/Web/Web_Languages/HTML/Q_20559098.html


:)  Happy hacking.

Tom
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now