Solved

username & password

Posted on 2000-05-05
5
361 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
[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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syslog text file into database or into .CSV 19 195
compress files in RAR using perl 13 94
Matching a random pattern with one common character 2 100
Perl Versus AWK? 7 99
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

751 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