Click to See Complete Forum and Search --> : please help - password java script


wendyteach
12-18-2002, 09:13 AM
Does anyone know of a simple script that would allow me to to
1. asks for a username
2. username = filename (website would be directed
to stupid.html if the user entered the name
"stupid")
3. ability to asign several of these
4. doesn't have to be all that secure - just needs to work

I know how to do the little password script that
uses the name of the password protected page as
the password.... that's basically what i want
except I want to be able to type in many names
for many different pages. I looked for such a
script but couldn't find one - any ideas how to
modify the single password script? One of my
clients asked for this and doesn't care if its
secure (i know - i don't see the point either -
but it's what he wants) PLEASE HELP!
THANKS!!!
wendy

AdamGundry
12-18-2002, 09:58 AM
You could use a script like this:

var UserStr = document.formname.fieldname.value;
location.replace(UserStr + '.html');

You could probably add simple validation to this by checking for allowed values of the variable - at the moment it will allow an incorrect entry, and return a 404.

Secure this isn't, but it should work.

Adam

wendyteach
12-18-2002, 11:32 AM
I REALLY appreciate your help.
I'm just learning java script, so can you give a bit more detail about where to place, and how to set up the script. Also, how I might place my own wording in the username request area. THANK YOU!!!
wendy

swon
12-18-2002, 02:15 PM
Hi Wendy,

for example:
password = demo.;
So, your next site must be named demo.html

here's the script:

<script language="JavaScript">
<!--
function passthrough()
{
var UserStr = window.prompt("Please insert your password");
window.location.href = UserStr+".html";
}
//-->
</script>
<noscript></noscript>
<body>
<button onClick="passthrough()">insert your password</button>
</body>

wendyteach
12-18-2002, 02:42 PM
Oh my gosh!!! You rule!!!!
That works perfectly...
one more question though (as I said, this is all new to me),
How do I get rid of the button and have it simply be a message link that I have in place on the website... like "click here to enter your name"...
I tried altering it myself, and i got rid of the button, but it threw all my graphics off.
I am sure that it is something real simple that I am overlooking.
THANKS AGAIN!!!! your are so smart...
wendy

swon
12-18-2002, 03:02 PM
Do you mean something like that?

<a href="www.dynamicdrive.com" onClick="passthrough();return false">insert your password</a>

replace this link with the button

wendyteach
12-18-2002, 05:07 PM
AWESOME!!!!

That's exactly what I needed.
THANK YOU THANK YOU THANK YOU
wendy

wendyteach
12-18-2002, 05:14 PM
ok - I know I said one more question but....
can I customize the error return when a bad password/filename is entered?
It's no big deal if I can't .....just thought it would be cool.
wendy

swon
12-18-2002, 05:24 PM
Jo Wendy,
The problem is that the passwordscript is in the html-page, you can't give a string to proof the password width the entered, cause anybody can see it in the source (sure, You can mix the string with those methods, but it'll never be secure enough). For a secure an good solution you need Server Side Languages like PHP or ASP.

Please excuse my english ;-)

Beach Bum
12-18-2002, 06:35 PM
try adding this to the function. this validates the input. in this case the input must begin with "abc". if it does not then errorpage.htm gets loaded.

however, if the person enters something that begins with "abc" that is still not valid then you still get the not found page.

sort of cheap validation that gives you an error page if you have no clue what to enter. of course when using this then all your valid pages must start with "abc" (or what ever you change it to).

testValue = /^abc\w+/; // value must begin with abc
if (testValue.test(UserStr)) {
window.location.href = UserStr+".html";
} else {
self.location.replace("errorpage.htm");
}

wendyteach
12-18-2002, 11:18 PM
thanks you guys!!!
:-)
wendy