Solved

username & password

Posted on 2000-05-05
5
359 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Perl script to parse log and delete the file 17 177
rename outfile before writing 2 74
Regex rule to match two different url 5 74
Perl tar error 8 66
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…

856 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