It worked perfectly but now instead of having the CGI do everything, I have an HTML form passing data to this CGI and now it's not working. The only difference between this and the original is it doesn't load a form to sign in with in the CGI script unless you type in the wrong information, it requests data form my HTML form instead.
No errors are present but the cookies are NOT setting if they login with the right info. And if the HTML form is submitted emtpy, it prints "test" instead of erroring out and doesn't print the login form.
Do you see what went wrong and what needs to be changed in order to make this take form data from an HTML form and work?
#!/usr/bin/perl use warnings; use strict; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); ####### # collect data from form ####### my $username = param("username"); my $password = param("password"); ######### # Cookie junk ######### my $cookiename = "filemanager"; my $pass= param('pass'); my $tasty = cookie($cookiename); use DB_File; my %users; my $users = "users.db"; # location of database tie %users, "DB_File", "$users", O_CREAT|O_RDWR, 0644 or die "Cannot o +pen file 'default.db': $!\n"; my ($savedpassword, $name, $email, $website, $start) = split(/::/, $us +ers{$username}); ###################################################################### +######################################### # COOKIE CHECKING ###################################################################### +######################################### # First check if we saved a cookie last time if($tasty) { print header(-expires=>'now'), start_html("Link Popularity Checker v1.8 Console"); &processing; print end_html; exit; } ###################################################################### +################################## # Password checking ###################################################################### +################################## unless ($password eq $savedpassword) { print header(-expires=>'now'), start_html("Login"); print <<"FORM"; <table border="2" width="181" bgcolor="#AAAAAA"> <tr> <td bgcolor="#CC0000" valign="bottom"><font color="#FFFFFF" fac +e="Arial, Helvetica, sans-serif">Client Login </font></td> </tr> <tr> <td valign="top"> <table width="181" border="0" align="center"> <form action="/cgi-bin/member/login.cgi" method="post"> <tr> <td width="59">username</td> <td width="122" valign="top"><input name="username" type="t +ext" size="15"></td> </tr> <tr> <td>password</td> <td valign="top"><input name="password" type="password" siz +e="15"></td> </tr> <tr> <td> </td> <td valign="top"><div align="right"> <input type="submit" name="Submit" value="Log In"> </div></td> </tr> </form> </table> FORM if (param()) { my $username = param("username"); my $password = param("password"); if (exists $users{$username}) { my $data = $users{$username}; my ($savedpassword, $name, $email, $website, $start) = split( +/::/, $users{$username}); if ($password ne $savedpassword) { print "<b>Wrong password!</b>"; exit; } } } else { print "username does not exist"; exit; } } ###################################################################### +################################## # Cookie setting ###################################################################### +################################## my $cookie = cookie( -NAME=> $cookiename, -VALUE=> $pass, ); print header(-COOKIE => $cookie, -expires=>'now'); print start_html("Going through here"); &processing; sub processing { print "test"; } ########### END PROCESSING SUB HERE exit;
In reply to CGI login issues by sulfericacid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |