我正在使用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