?
Solved

simple password protect for web page?

Posted on 2003-03-21
17
Medium Priority
?
272 Views
Last Modified: 2010-04-09
I have a web page I want to require a password to get to.

What is the simplest way I can do this?

0
Comment
Question by:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
17 Comments
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 8182401
I am fine with a JavaScript solution.
0
 
LVL 3

Expert Comment

by:superslamwich
ID: 8182423
<script>
<!--
  ans = prompt('What is the password??')
  if(ans=='opensesame') {
  }
  else  {
    self.location='wrongpassword.html'
  }
//-->
</script>
0
 
LVL 3

Expert Comment

by:superslamwich
ID: 8182425
change opensesame to whatever the password should be.
0
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 
LVL 5

Author Comment

by:Tom Knowlton
ID: 8182461
If I put your code into its own .js file...how do I call the function from my html code?
0
 
LVL 3

Expert Comment

by:superslamwich
ID: 8182467
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
 
LVL 3

Expert Comment

by:superslamwich
ID: 8182473
<script language='javascript' src='thejs.js'>
</script>

should do the job
0
 
LVL 3

Expert Comment

by:superslamwich
ID: 8182485
thejs.js is whatever your javascript file is named
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 8182491
<script language='javascript' src='thejs.js'>
</script>


I understand this, but how do I call the function inside  the thejs.js file?
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 8182496
If JavaScript is not secure, what would you recommend?

0
 
LVL 3

Expert Comment

by:superslamwich
ID: 8182537
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
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 8182547
Understood.

Oh...and how do I call the JavaScript function from HTML after I have referenced the JS file?
0
 
LVL 17

Expert Comment

by:dorward
ID: 8182585
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 8182613
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
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 8182674
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
 
LVL 7

Accepted Solution

by:
cubrovic earned 500 total points
ID: 8182986
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
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 8183301
I like this solution a lot.  Not bullet-proof, but a little more secure.

Thank you everyone.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 8183478
For more points see this question:

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


:)  Happy hacking.

Tom
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question