Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.
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 #-----------------------------------------
I mustn't be reading the password file properly, I don't know.... Here's the html code for the form.
<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>

In reply to Login Please!! by eoin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-24 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found