Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you do a javascript password box?

Status
Not open for further replies.

meeble

Programmer
Sep 24, 2002
137
GB
Hello,

I have a box and when the user enters a password and presses submit I want them to go to a page.

I can do this for one password but I have 30 passwords and I want the user to be able to enter any of these and be taken to the same page.

So I guess I need an array or something but I don't know how to do those.

From a security point of view, it doesn't have to be secure. I'm not worried about them viewing the source or anything.

Regards,

James
 
If you mean that it's okay to have the passwords hard-coded into the source code, even though it means anyone could see them (which seems odd, but that sounds like what you're saying), then I'll advise what I usually do in such situations:

(1) create a string:

var passwordString = "*";

(2) append to the string the passwords:

for(var i=0; i<passwords.length; i++)
passwordString += passwords + "*";

Notice the list will be *-delimited. Every password in the list will have an asterisk in front AND behind it.

(3) Then, compare the user's entry to the passwordString:

if(passwordString.indexOf("*"+userEntry.value+"*") > -1)
//continue
else
alert("Password not accepted!");

Obviously, for this example, you'll need an array with the passwords in it and a way to get the user's entry.

'hope that helps.

--Dave
 
Thanks. Not really sure what you mean but I'll keep looking into it.

This is just to highlight the functionality of the password system in the testing phase.

Eventually the password will be done with PHP and a MySQL database.
 
o.k, i will modify dave's code:


//userEntry.value is the form's field...
//Define the password
passwordString="*Password1*Password2*Password3*"
if(passwordString.indexOf("*"+userEntry.value+"*") > -1)
//continue
else
alert("Password not accepted!");


Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top