eoin has asked for the wisdom of the Perl Monks concerning the following question:
I have this basic user authentication program here but it won't work. I continuesly get an invalid user\password message.
The password file, 'pass', is written like this
(example)
eoin pass
test 1234
admin sys
Here's the code for the program. a fellow monk help me structure it because this is my first proper cgi prog.
I mustn't be reading the password file properly, I don't know.... Here's the html code for the form.use strict; use warnings; use CGI; my $q = new CGI; my $user = $q->param('user'); my $password = $q->param('pass'); #----------------------------------------- #START OF MAIN PROGRAM #----------------------------------------- my ($title,$body); if ( &verify($user,$password) eq "Valid" ){ ($title,$body) = &valid(); } else { ($title,$body) = &fail(); }; print qq(Content-type: text/html\n <html> <head><title>$title</title></head> $body </html>); #----------------------------------------- #END OF MAIN PROGRAM:BEGIN OF VERIFICATION #----------------------------------------- sub verify{ my ($user,$password) = @_; open(PASS, "pass") or die "Couldn't find password file.\n"; while(<PASS>){ chomp; my ($ur,$ps) = split(/\t/, $_, 2); if ( ($ur eq $user) && ($ps eq $password) ){ close PASS; return "Valid"; } } close PASS; return "notValid"; } #----------------------------------------- #IF VALID #----------------------------------------- sub valid { my $title = "Login successful !"; my $body = q(<body bgcolor="black" text="red"> <h3>Login succesful!</h3><br><br> <a href="www.eircom.net"><h2>Click here to continue</h2></a><hr> </body>); return ($title,$body); } #----------------------------------------- #IF NOT VALID #----------------------------------------- sub fail { my $title = "Login unsuccessful !"; my $body = q(<body bgcolor="black" text="red"> Invalid username\password.<br> Please try again.<br><br><hr> <form method=POST action="http://eoinmurphy.netfirms.com/cgi-bin/main. +pl"> User Name: <input name="user" size="30"><br> Password: <input name="pass" size="30"><br> <input type="submit" value="Send"></form><hr> </body>); return ($title,$body); } #----------------------------------------- #END #-----------------------------------------
<form action="http://eoinmurphy.netfirms.com/cgi-bin/main.cgi" method= +"POST"> <p>User Name: <input type="text" size="30" name="user"><br> Password:<h7>.</h7> <input type="text" size="30" name="pass"><br> <input type="submit" value="Send"> </p> <hr> </form>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Login Please!!
by Trimbach (Curate) on Dec 30, 2002 at 22:50 UTC | |
by eoin (Monk) on Dec 30, 2002 at 23:44 UTC | |
by gjb (Vicar) on Dec 31, 2002 at 00:13 UTC | |
by eoin (Monk) on Dec 31, 2002 at 11:13 UTC | |
Re: Login Please!!
by dws (Chancellor) on Dec 30, 2002 at 23:54 UTC | |
Re: Login Please!!
by poj (Abbot) on Dec 30, 2002 at 23:11 UTC | |
by iguanodon (Priest) on Dec 31, 2002 at 03:11 UTC |
Back to
Seekers of Perl Wisdom