I've tried using sha
but its not working maybe I've done something wrong.
In the database password field I have varchar(65)
If I type that long "65" it works I can login but the normal password is not hashing.
<?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;
}
?>
the function on login script
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);
}
I forgot to tell that I have login script already what I am trying to do is to integrate it to my video chat.