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

hwnd
User
Apr 1, 2011, 8:59 PM
Views: 14546
|
|
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
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. Also I tried this with just selected the id and it works fine.
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 hwnd
(User) on Apr 2, 2011, 2:18 AM
|
|
Post edited by hwnd
(User) on Apr 2, 2011, 5:46 AM
|
|
Post edited by hwnd
(User) on Apr 2, 2011, 6:03 AM
|
|
Post edited by hwnd
(User) on Apr 2, 2011, 1:55 PM
|
|
|  |