我不熟悉 Wordpress 对密码使用哪种散列方法,但我认为它是安全且不可逆的。由于散列是一种单向算法,因此散列密码无法转换为其 MD5 等效密码。
这是我给你的建议:
在您的新网站的用户表中添加一个using_md5_flag布尔列,并使用默认值0。将密码从 Wordpress 复制到一个列中wppassword,并创建一个名为md5password当用户登录系统时执行以下代码的列(假设 Datamapper ORM,如果需要,转换为 Active Record):
$u = new User();
$u->where('username', $this->input->post('username'))->get();
$y = new User();
$y->where('username', $this->input->post('username'));
if($u->using_md5_flag){
    /*the flag is 1*/
    $y->where('md5password', md5($this->input->post('password')));
    $y->get();
    if($y->exists()) echo "setting cookie and redirecting to logged in area";
    else echo "Wrong credentials!";
}
else{
    /*the flag is 0, use wordpress's hashing algorithm (not sure what this is)*/
    $y->where('wppassword', wp_hashing_algo($this->input->post('password')));
    $y->get();
    if($y->exists()){
        /*set the using_md5_flag flag so next time they log in it will ignore wp's*/
        $y->using_md5_flag = 1;
        /*set the new md5 password.*/
        $y->md5password = md5($this->input->post('password'));
        $y->save();
        echo "setting cookie and redirecting to logged in area";
    }
    else{
        echo "Wrong credentials.";
    }
}
此代码尚未经过测试,我是在 StackOverflow 的编辑器中编写的……但这是我将慢速转换为更安全的哈希所采用的方法。最后,如果您正在寻找一个真正安全的哈希,请查看 Bcrypt ( phpass ),它更能抵抗彩虹表攻击。
更新 1:如果你需要在 CodeIgniter 中使用 Phpass 库,你可以在这里找到我修改的副本(我添加了一个构造函数)。将其放入libraries/Phpass.php您可以使用以下方法在控制器中使用该库:
$this->load->library("phpass", array("iteration_count_log2" => 8, "portable_hashes" => FALSE));
$check = $this->phpass->CheckPassword($this->input->post('password'), $u->password);
if($check) /*logged in*/
else /*wrong credentials.*/
当您下载 Phpass 文件时,它会附带一个test.php演示函数如何工作的文件。我建议审查它。