CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: DBI: Re: [FishMonger] Is there a better way to write this to check login information?: Edit Log



recruiter
User

Apr 1, 2011, 8:59 PM


Views: 15687
Re: [FishMonger] Is there a better way to write this to check login information?

It's giving an error using this statement -> Software error: Use of uninitialized value in string eq at loginb.pl line 57


Code
return ($name eq $user and $pw eq $pass) ? 1 : 0;


I'm guessing the data is not what it thinks it is. I don't need to check the return values from the database because they'll only be defined if the username and password match. It won't return a record, so $id, $name and $pw will be undef if the password and username don't match. So I just check if id is defined which is the same as asking did it return a record.


Code
return (defined $id);


Also I tried this with just selected the id and it works fine.


Code
sub authenticate {  

my $user = shift;
my $pass = shift;

return 0 unless $user && $pass;

my $dbh = DBI->connect("DBI:mysql:hwnd_news:localhost", "hwnd_hwnd", "b71lnk")
or die $DBI::errstr;

my $sth = $dbh->prepare(
"SELECT id from news_users
WHERE name = ? AND pass = ?
LIMIT 1"
);
$sth->execute($user, $pass);

my ( $id ) = $sth->fetchrow_array();
$dbh->disconnect;

return ($id) ? 1 : 0

}



(This post was edited by hwnd on Apr 2, 2011, 1:55 PM)


Edit Log:
Post edited by recruiter (User) on Apr 2, 2011, 2:18 AM
Post edited by recruiter (User) on Apr 2, 2011, 5:46 AM
Post edited by recruiter (User) on Apr 2, 2011, 6:03 AM
Post edited by recruiter (User) on Apr 2, 2011, 1:55 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives