Gossamer Forum
Home : General : Databases and SQL :

cgi-session-mysql member login script

Quote Reply
cgi-session-mysql member login script
any one could show me a working sample of cgi-session-mysql member login script.
the code at http://search.cpan.org/.../Session/CookBook.pm
is only store db on disk , i have convert it to mysql, however failed.

sub _load_profile {
my ($lg_name, $lg_psswd) = @_;
local $/ = "\n";
unless (sysopen(PROFILE, "profiles.txt", O_RDONLY) ) {
die "Couldn't open profiles.txt: $!");
}
while ( <PROFILES> ) {
/^(\n|#)/ and next;
chomp;
my ($n, $p, $e) = split "\s+";
if ( ($n eq $lg_name) && ($p eq $lg_psswd) ) {
my $p_mask = "x" . length($p);
return {username=>$n, password=>$p_mask, email=>$e};
}
}
close(PROFILE);
return undef;
}



below are converted version
sub _load_profile {
#my ($lg_name, $lg_psswd) = @_;
if ($lg_psswd and $lg_name) {
#
$statement="SELECT * from userprofile";
$sth = $dbh->prepare("$statement")
or die "Can't prepare $statement: $dbh->errstr\n";
#$rv = $sth->execute("$lg_name")
#or die "can't execute the query: $sth->errstr";
while (my $ref = $sth->fetchrow_hashref) {
$xusername = $ref->{username};
$xpassword = $ref->{password};
$xemail = $ref->{email};
#####Check if username and password exist
if (($xusername eq $lg_name) && ($xpassword eq $lg_psswd))
{
my $p_mask = "x" . length($xpassword);
return {username=>$xusername, password=>$p_mask, email=>$xemail};
#$sth->finish();
return undef;
}
######
}
}
} #end if