How can I convert password in core from MD5 to SHA1? I got a new cms that is in md5 but my user accounts are in SHA1. Help would be appreciated.
New CMS (MD5/BCRYPT):
OLD CMS - SHA1:
My objective is to have the new CMS working with my old accounts securely. I do not want to be hacked and I heard md5 is not secure. Thank you!
New CMS (MD5/BCRYPT):
Code:
class User
{
public static function checkUser($password, $passwordDb, $username)
{
if (substr($passwordDb, 0, 1) == "$")
{
if (password_verify($password, $passwordDb))
{
return true;
}
return false;
}
else
{
if (md5($password) == $passwordDb)
{
$updateUserHash = DB::Query("UPDATE users SET password = '".self::hashed($password)."' WHERE username = '".filter(DB::Escape($username))."'");
return true;
}
return false;
}
}
public static function hashed($password)
{
return password_hash($password, PASSWORD_BCRYPT);
}
public static function validName($username)
{
if(strlen($username) <= 12 && strlen($username) >= 3 && ctype_alnum($username))
{
return true;
}
return false;
}
PHP:
function ValidateUser($username, $password)
{
return mysql_num_rows(dbquery("SELECT null FROM users WHERE username = '" . $username . "' AND password = '" . $password. "' LIMIT 1"));
}
function UserHash($password, $username)
{
return sha1(md5($password) . strtolower($username));
}
function HasNewCrypto($username)
{
if(mysql_result(mysql_query("SELECT newcrypto FROM users WHERE username = '" . $username . "'"), 0) == "0")
{
return true;
}
return false;
}
function CryptoValidate($username, $password)
{
return mysql_num_rows(dbquery("SELECT null FROM users WHERE username = '" . $username . "' AND password = '" . $password. "' LIMIT 1"));
}