Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The creation of that table is
The login script itself is belowmy $sth = $dbh->prepare( "CREATE TABLE IF NOT EXISTS admin ( id int auto_increment not null, username VARCHAR(25) DEFAULT 'admin' NOT NULL, password VARCHAR(36) DEFAULT '1a1dc91c907325c69271ddf0c944bc72' + NOT NULL, primary key (id) )"); $sth->execute(); if ($sth->errstr) { print $sth->errstr; } else { print "Admin table was setup"; }
Anyone have any ideas why it may be failing? I know the form fields are ligned up because doing a test print I get#!/usr/bin/perl use warnings; use strict; use CGI::Carp 'fatalsToBrowser'; use CGI qw/:standard/; use Digest::MD5 qw(md5_hex); use CGI::Cookie; use DBI; #################### # Configuration section #################### my $dbase = "spyders_test"; my $mysql_user = "spyders_admin"; my $mysql_pass = "pass"; #################### # Do NOT edit below this line #################### ###### # Connecting to our database ###### my $dbh = DBI->connect("DBI:mysql:$dbase", $mysql_user, $mysql_pass) o +r print DBI=>"errstr"; ####### # Check to see if they have a login cookie ####### my %cookies = fetch CGI::Cookie; if (defined($cookies{'user_id'})) { print header, start_html("Login"); print "You are already logged in. Please wait while you're redirec +ted..."; print "<script>window.location = 'index.cgi';</script>\n"; exit; } ####### # The form was submitted, let's process it ####### if (param()) { my $username = param("username"); my $password = param("password"); $password = md5_hex($password); my $data = qq(SELECT * FROM admin WHERE username = "$username" AND p +assword = "$password"); my $sth = $dbh->prepare($data); $sth->execute() or die $dbh->errstr; if ($sth->rows < 1) { print header, start_html("Authentication Failed"); print "User was $username: password was $password<p>"; print "<b>Your username or password were incorrect.</b> <p>Please + click Back to continue</p>"; exit; } else { while ($data = $sth->fetchrow_hashref) { my $auth_user = new CGI::Cookie(-name => 'user_id', -value + => $username); my $auth_pass = new CGI::Cookie(-name => 'user_pass', -value + => $password); print "Set-Cookie: $auth_user\n"; print "Set-Cookie: $auth_pass\n"; print header, start_html("Login"); print "Welcome " . $username . ", you have successfully logged in +.\n"; print "<script>window.location = 'admin.pl';</script>\n"; } } }
Thank youUser was admin: password was 1a1dc91c907325c69271ddf0c944bc72 Your username or password were incorrect. Please click Back to continue
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: faulty small cgi/mysql login
by Animator (Hermit) on Feb 12, 2005 at 17:52 UTC | |
by Anonymous Monk on Feb 12, 2005 at 17:54 UTC | |
by Animator (Hermit) on Feb 12, 2005 at 17:56 UTC | |
by Anonymous Monk on Feb 12, 2005 at 18:06 UTC | |
|
Re: faulty small cgi/mysql login
by CountZero (Bishop) on Feb 12, 2005 at 19:58 UTC |