
abockover
Deleted
Sep 24, 2000, 7:58 AM
Post #1 of 3
(547 views)
|
|
Login script not working - Please Help
|
Can't Post
|
|
I am working on a simple login script for another program. The script displays a form with a text and password field asking for a username and password. Username and password is submitted and the script checks a flat file database for the correct username and password. If a correct username and password is given, their name is displayed. When I try the script, I can login only as the first user in the database: bob|1234|Bob Jones If I try to login as another user: joe|5678|Joe Shmoe I get a script generated error (goes back to the login page). It is only reading the firts line in the database. Could anyone help? If you would like to see the script in "action": http://www.crevasoft.com/login.pl username: bob password: 1234 username: joe password: 5678 Only bob will login. Below is the script +++++++++++++++++++++ <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> #!/usr/bin/perl &parse_form; $userlist = "users.txt"; $username = $input{'lg_username'}; $password = $input{'lg_password'}; print "Content Type: text/html\n\n"; open (USERS,"<$userlist"); @LST=<USERS>; close (USERS); foreach $user (@LST){ chomp($user); ($dl_username,$dl_password,$dl_name)=split(/\|/,$user); if($username eq $dl_username and $password eq $dl_password) { print "<html><body><h2><i>\n"; print "Hello, you are logged in as $dl_name\n"; print "</i></h2></body></html>\n"; exit(0); } else { &loginForm; exit(0); } } sub loginForm { print <<"EOF"; <html> <head> <title>Login</title> </head> <body> <h2>Login</h2><hr> <form action="login.pl" method="POST"> Username: <input type="text" name="lg_username"> <br> Password: <input type="password" name="lg_password"> <br> <input type="submit" value="Login"> </form> </body> </html> EOF exit(0); } sub parse_form { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); if (length($buffer) < 5) { $buffer = $ENV{QUERY_STRING}; } @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $input{$name} = $value; } } </pre><HR></BLOCKQUOTE> ++++++++++++++++++ Below is the flat file datbase the script is suppose to search for usernames and passwords ++++++++++++++++++ <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> bob|1234|Bob Jones joe|5678|Joe Shmoe lyn|9101|Lyn Gin </pre><HR></BLOCKQUOTE> ++++++++++++++++++ Thanks a lot, Aaron [This message has been edited by abockover (edited 09-24-2000).]
|