我正在使用moodle系统,但事实证明它使用md5盐哈希。我发现了一些来,所以也许你可以解释它给我,因为我只有PHP的基本知识。php代码md5哈希解释
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;
}
难道是很难改变它在进入简单的文本后,将成为哈希?
你的问题就没有意义了。完全不清楚你想要做什么。 – ceejayoz 2012-04-13 19:19:01
我正在创建一个java应用程序,它将连接到数据库并从中获取数据,但存在问题。使用网页注册的帐户密码已变更。上面的代码应该是它如何改变的方式。但我不明白,我想如果有人可以给我解释 – LTnewbie 2012-04-13 19:24:11
使用Moodle的网络服务API。不要直接使用数据库。 Moodle已经破碎了,因为它不会让事情变得更糟。 – Brad 2012-04-13 19:31:09