我正在使用moodle系统,但事实证明它使用md5 salt hashing。我找到了一些,所以也许你可以向我解释一下,因为我只有基本的 php 知识。
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;
}
输入简单文本后会变成散列,这很难改变吗?