我使用这个脚本来检查我的bb密码,但我得到这个错误:" NO "。我使用了mybb密码加密方法,但我不知道为什么这不起作用?
<?php
error_reporting(-1);
$MySQL_Host = "localhost";
$MySQL_User = "root";
$MySQL_Pass = "";
$MySQL_DB = "mybb";
$username = 'me';
$password = 'you';
mysql_connect("$MySQL_Host", "$MySQL_User", "$MySQL_Pass") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("$MySQL_DB") or die(mysql_error());
$result = mysql_query("SELECT uid, password, email FROM mybb_users WHERE username='".$username."' AND password='".md5(md5($salt).md5($password))."';");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
if( md5(md5($salt).md5($password)) == $result[ 0 ][ 'password' ] )
{
echo "yes" ;
//i need this option
return array( 'id' => $result[ 0 ][ 'uid' ],
'mail' => $result[ 0 ][ 'email' ],
'user' => $username
);
}
else
echo "no";
?>
$result[ 0 ][ 'password' ]
为空,因为您忘记获取:
$result = mysql_query("SELECT uid, password, email FROM mybb_users WHERE username='".$username."' AND password='".md5(md5($salt).md5($password))."';");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
$row = mysql_fetch_assoc($result);
现在检查记录是否存在:
if( $row !== false )
{
echo "yes" ;
//i need this option
return array(
'id' => $row[ 'uid' ],
'mail' => $row[ 'email' ],
'user' => $username
);
} else
echo "no";
你从哪里得到的$salt
?您还需要从数据库中获取盐(每个用户保存单独的盐),并使用该盐加密用户输入的密码,以比较数据库的密码。