PDA

Click to See Complete Forum and Search --> : JavaScript:Passwords


ajames
Apr 17th, 2005, 04:03 AM
I know that javascript isn't a reliable source for passwords, but can anyone give me a quick examlpe on how to to a password protected page?


P.s. most of my users will be stupid people who hardly know how to use IE properly, let alone know what the source means!

anotherVBnewbie
Apr 18th, 2005, 03:57 PM
Can't help you much with javascript to password protect a webpage but..

Have you considered using htaccess to password protect directories? Very secure, username/passwords are only stored server side and the server/browser will handle the negotiations for you, and simple to implemente.

sciguyryan
Apr 18th, 2005, 04:08 PM
Have a look at the attatched file.

That is a very secure example (Well, about as secure as you can get using Javascript).

Note: I did not write this but, thought you may find it useful :)

Cheers,

RyanJ

ajames
Apr 19th, 2005, 11:17 AM
any siimpler ones? something like:
"if password="easy" then goto www.blahblahblah.com"
it's not like i'm protecting nuclear silos, or personal documents, just a friends section sort of thing.
I know no-one in my school who knows about viewing the page source!

Brandoe85
Apr 19th, 2005, 06:46 PM
Try this out:


<html>
<head>
<script type="text/javascript">
function passwordProtect()
{
var pass = "somepassword";
var protect = prompt("Enter the password","");
if(protect != pass)
{
location.href="http://www.google.com";
}
else
{
location.href="http://www.vbforums.com";
}
}
onload=function(){passwordProtect();}
</script>
</head>
<body>
</body>
</html>

nkad
Apr 20th, 2005, 01:52 AM
Try this out:


<html>
<head>
<script type="text/javascript">
function passwordProtect()
{
var pass = "somepassword";
var protect = prompt("Enter the password","");
if(protect != pass)
{
location.href="http://www.google.com";
}
else
{
location.href="http://www.vbforums.com";
}
}
onload=function(){passwordProtect();}
</script>
</head>
<body>
</body>
</html>


Now I am going to be a little critical here. That code there seems kind of redundant in that you created a closure to call a function.

Don't take it the wrong way, lol, it just struck me funny when I saw that.

ajames, another option might be (if it is available to you), create an ASP page that contains you passwords that you need to authenticate with, then create an HTML form that POSTS the username and password to the ASP page. Doing it this way would keep people from trying to break in.

Just thought I would mention it.

ajames
Apr 20th, 2005, 01:38 PM
tried asp, but is way to complicated as i have no server (yet), however, the code that was supplied wouldn't let me enter anything in! can someone try and change this?

thanks in advance.

Brandoe85
Apr 22nd, 2005, 12:47 PM
Hmmm, it's working for me in IE6 and FF1.0.1. Did the prompt pop up at all? Or what happend exactly? Maybe javascript is disabled?

Good luck;