2014-03-31 125 views
0

我正在爲一類項目的網站,但不明白爲什麼即時得到這個錯誤。 到目前爲止,我已經 裸詞發現,其中運營商預計將在用戶login.cgi線14,也同樣的錯誤和同一行「$用戶名和」近「距離USR用戶名」 我不是能找到任何有用的搜索。如果任何人都可以幫助它是極大的讚賞SQL查詢的用戶名和密碼

$username = $formdata{'username'}; 
$password = $formdata{'password'}; 
$msp = "password"; 
$msdb = "databasename"; 
$msusr = "usrname"; 
$dbh = DBI ->connect("DBI:mysql:$msdb", "$msusr", "$msp"); 
$check_user = $dbh->selectrow_array(select username from usr WHERE email = $username AND usrpswrd = crypt $password, codetype); 

這是儘可能的Perl檢查代碼時獲取並給出了錯誤

回答

2

您應該封裝撇號的SQL。就像這樣:

$check_user = $dbh->selectrow_array("select username from usr WHERE email = $username AND usrpswrd = crypt $password",... 

(實際上這個地穴$密碼不好看......你應該選擇綁定變量,而不是創建一個大的查詢字符串從用戶進入室內這可以輸入。是一個可能的安全漏洞。(搜索SQL注入。))

0

你需要引用選擇

"select username from usr WHERE email = '$username' 
    AND usrpswrd = '" . crypt($password) . "'" 

你也想加入

use strict; 
use warnings; 

在腳本

2

的幾個問題的頂部:

會建議這些變化(未測試):

use strict; 
use warnings; 

... 

my $msp = "password"; 
my $msdb = "databasename"; 
my $msusr = "usrname"; 
my $dbh = DBI->connect("DBI:mysql:$msdb", "$msusr", "$msp") 
    or die "DB connect failed: $DBI::errstr"; 

my $username = $formdata{'username'}; 
my $password = $formdata{'password'}; 

my $sth = $dbh->prepare(q{select username from usr WHERE email=? AND usrpswrd=?}); 
$sth->execute($username, crypt($password)) or die $dbh->errstr; 
my ($check_user) = $sth->fetchrow_array;