dtttlua7165 2018-06-28 22:19
浏览 488

转换密码哈希算法

I coded up an app with a backend in PhP and got a few users. All of them have passwords, which were hashed using PhP's crypt function with the same salt every time of "PASSWORD_DEFAULT".

Now, because that code was very bad, I am transitioning to JavaScript where to hash passwords I am using the bcrypt Node Module with a randomly generated salt.

I was wondering, is there any way to save the old user's logins and make them valid even with the new hash, or are they gone forever?

EDIT FOR CODE:

Old PhP Code:

$stmt = $this->db->prepare(
        "INSERT INTO USERS (deviceID, latitude, longitude, username, password, date_reg) VALUES (?, ?, ?, ?, ?, CURDATE());");
        $stmt->bind_param("sddss", $deviceID, $rounded_down_lat, $rounded_down_long, $username, crypt($password, "PASSWORD_DEFAULT"));

New JavaScript/Node.js Code:

    add_user(deviceID, username, unencrypt_password, latitude, longitude, dob, gender) {
        latitude = latitude - latitude % process.env.ERR_RANGE + Number(process.env.ERR_RANGE);
        longitude = longitude - longitude % process.env.ERR_RANGE + Number(process.env.ERR_RANGE);
        var salt = bcrypt.genSaltSync(saltRounds);
        var password = bcrypt.hashSync(unencrypt_password, salt);
        var add_user_query = mysql.format(add_user_sql, [deviceID, latitude, longitude, username, password, salt, new Date(), dob, gender]);
        ...
    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料