现在我正在尝试检查 MysSql 数据库中的密码是否相同。但我失败了,我不明白为什么。
$username = 'blablabla';
$password = 'blablabla.';
$salt = 'blablabla';
$new = md5($password.md5($salt));
echo($new);
$q=mysql_query("SELECT * FROM mdl_user WHERE username = '$username' AND password = '$new'");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
在定义盐字的配置文件中,我使用了与上面相同的内容。
已编辑:是否可以从此代码中获取哈希算法?
function validate_internal_user_password($user, $password) {
global $CFG;
if (!isset($CFG->passwordsaltmain)) {
$CFG->passwordsaltmain = '';
}
$validated = false;
if ($user->password === 'not cached') {
// internal password is not used at all, it can not validate
} else if ($user->password === md5($password.$CFG->passwordsaltmain)
or $user->password === md5($password)
or $user->password === md5(addslashes($password).$CFG->passwordsaltmain)
or $user->password === md5(addslashes($password))) {
// note: we are intentionally using the addslashes() here because we
// need to accept old password hashes of passwords with magic quotes
$validated = true;
} else {
for ($i=1; $i<=20; $i++) { //20 alternative salts should be enough, right?
$alt = 'passwordsaltalt'.$i;
if (!empty($CFG->$alt)) {
if ($user->password === md5($password.$CFG->$alt) or $user->password === md5(addslashes($password).$CFG->$alt)) {
$validated = true;
break;
}
}
}
}
if ($validated) {
// force update of password hash using latest main password salt and encoding if needed
update_internal_user_password($user, $password);
}
return $validated;
编辑 我试过这个代码:
$username = 'admin';
$password = 'Vidsodis25.'+'Karolina';
$new = md5($password);
echo($new);
$q=mysql_query("SELECT * FROM mdl_user WHERE password = '$new'");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
数据库使用相同的盐词 Karolina。但是还是找不到正确的。