Solved

username & password

Posted on 2000-05-05
5
360 Views
Last Modified: 2010-03-05
I have created two arrays one for username and the other for password as shown below:

@username=("ABC","DEF","GHI");
@password=("101","102","103");

During the register proces the user is then given a username and password from above.

They then have to enter their username and password into a form which then gets the appropriate pl file to check whether the username and password is valid by checking what the user has entered in the form to what is entered in the array if their is a match then the user gains access to the system if not then they dont.

The form uses the get method so the Query_string is within $FORM_DATA.

The code I have typed in at the moment does not produce any errors but doesnt work properly the incorrect username keeps coming up:
here is the code:

The $username is trying to refer to the array.  The username is the name of the field in the HTML form.

if (exists $username{$FORM_DATA{'username'}}) {
      print"Correct password<BR>";
}
else {
print "Incorrect username","\n";
}

Any help will be greatly appreciated, or any alternative's to the above code.

Thank you.

email to:anne.smith@lineone.net
0
Comment
Question by:annesmith
  • 3
5 Comments
 

Expert Comment

by:sniperrus
ID: 2780789
For starters, why use two arrays, this seems like it's crying for a %Hash. If you create a hash table with the user names as the keys and the passwords as the values then you can simply check

if ($password eq $hash{$username})
{
print"Correct password<BR>";
}
else {
print "Incorrect username","\n";
}

it's also faster than exists.
0
 

Expert Comment

by:sniperrus
ID: 2780793
sniperrus changed the proposed answer to a comment
0
 

Accepted Solution

by:
sniperrus earned 50 total points
ID: 2780798
Sorry a quick error fix:

if ($form{password} eq $hash{$form{username}})
{
print"Correct password<BR>";
}
else {
print "Incorrect username","\n";
}


0
 
LVL 84

Expert Comment

by:ozo
ID: 2781665
@hash{@username} = @password;
0
 

Author Comment

by:annesmith
ID: 2784098
Thank you very much sniperrus.  That code you specified works a treat.  Excelllent.  Thanks very much for your help.

Anne.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

685 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