Solved

username & password

Posted on 2000-05-05
5
357 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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 …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now