我试过使用sha
,但它不起作用,也许我做错了什么。
在我的数据库密码字段中varchar(65)
如果我输入这么长的“65”,它可以登录,但正常密码不是散列。
<?php
require_once '../../../common/server/php/settings.php';
//Connect to users database
$db = mysql_connect('localhost','root','test') or die(mysql_error());
mysql_select_db('test',$db) or die(mysql_error());
//Init request parameters
$userName = (isset($_REQUEST["user_name"])) ? urldecode($_REQUEST["user_name"]) : "";
$password = (isset($_REQUEST["password"])) ? urldecode($_REQUEST["password"]) : "";
$uid = (isset($_REQUEST["uid"])) ? urldecode($_REQUEST["uid"]) : "";
$password = sha1($password);
//Check if user filled login and password in the login screen (Chat authorization)
if($userName != "" && $password != "")
{
$sql = "SELECT * FROM users WHERE username='".$userName."' AND password='".$password."'";
}
//session/cookie base authorization (Auto login)
else if ($_SESSION['user_id']!="")
{
$sql = "SELECT * FROM users WHERE id='".$_SESSION["user_id"]."'";
}
// Non session/cookie based autologin authorization
else if ($uid!="")
{
$sql = "SELECT * FROM users WHERE id='".$_GET['uid']."'";
}
else
{
echo '<auth error="AUTH_ERROR" />';
exit;
}
//Select user data
$result = mysql_query($sql,$db);
if(mysql_num_rows($result)==1)
{
//User found. get user info
$usersInfo = mysql_fetch_array($result);
$photo = FLASHCOMS_HTTP_ROOT.'common/images/User1_120.png';
$photoModeImage = FLASHCOMS_HTTP_ROOT.'common/images/User1_40.png';
$answer = '<auth>';
$answer .= '<userName><![CDATA['.$userName.']]></userName>';
$answer .= '<gender>male</gender>';
$answer .= '<age>'.$userInfo['age'].'</age>';
$answer .= '<level>regular</level>';
$answer .= '<photo><![CDATA['.$photo.']]></photo>';
$answer .= '<photoModeImage><![CDATA['.$photoModeImage.']]></photoModeImage>';
$answer .= '</auth>';
echo $answer;
exit;
}
else
{
//User not found OR authorization failed
echo '<auth error="AUTH_ERROR" />';
exit;
}
?>
登录脚本上的功能
function generateHash($plainText, $salt = null)
{
if ($salt === null)
{
$salt = substr(md5(uniqid(rand(), true)), 0, 25);
}
else
{
$salt = substr($salt, 0, 25);
}
return $salt . sha1($salt . $plainText);
}
我忘了告诉我已经有登录脚本了,我想做的是将它集成到我的视频聊天中。