Solved

username & password

Posted on 2000-05-05
5
355 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
Comment Utility
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
Comment Utility
sniperrus changed the proposed answer to a comment
0
 

Accepted Solution

by:
sniperrus earned 50 total points
Comment Utility
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
Comment Utility
@hash{@username} = @password;
0
 

Author Comment

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

Anne.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

10 Experts available now in Live!

Get 1:1 Help Now