如何使用jBcrypt检查bcrypt密码?(将存储空间从Parse.com移至Firebase) [英] How to check bcrypt password using jBcrypt? (move storage from Parse.com to Firebase)

查看:112
本文介绍了如何使用jBcrypt检查bcrypt密码?(将存储空间从Parse.com移至Firebase)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些开发人员需要将存储从parse.com移至另一台服务器.

Some of developers need to move storage from parse.com to another servers.

当我从解析导出数据时,我得到json数据.此json数据具有加密密码(bcrypt),例如:

When I exported my data from parse, I get json data. This json data has encrypted passwords (bcrypt) like:

$ 2a $ 10 $ pcR4SaZd3PMD/nXQKMssxupMLncDoFwfU7avg/wdpLVChNqGOXbLu

$2a$10$pcR4SaZd3PMD/nXQKMssxupMLncDoFwfU7avg/wdpLVChNqGOXbLu

我试图理解,在这种情况下如何从用户检查密码.

I try to understand, how to check password from user in this case.

我这样使用jBcrypt:

I using jBcrypt like this:

import org.mindrot.jbcrypt.BCrypt;

public class Main {

    public static void main(String[] args) {
        String candidate = "$2a$10$pcR4SaZd3PMD/nXQKMssxupMLncDoFwfU7avg/wdpLVChNqGOXbLu";
        String password = "123";

        String hashed = BCrypt.hashpw(password, BCrypt.gensalt());

        if (BCrypt.checkpw(candidate, hashed)) {
            System.out.println("It matches");
        }

        else {
            System.out.println("It does not match");
        }
    }
}

在这种情况下,密码不多.但是,如果我们转到 https://www.dailycred.com/article/bcrypt-calculator并尝试使用带有散列的候选字符串和"123"密码的BCrypt Tester都是可以的.

In this case passwords don't much. But if we go to https://www.dailycred.com/article/bcrypt-calculator and try to use BCrypt Tester with hashed, candidate strings and "123" password it's all ok.

我如何理解用户密码是否与bcrypt字符串匹配?

How can I understand do user's password match with bcrypt string or not?

推荐答案

BCrypt.checkpw()将纯文本密码作为第一个参数,然后对其进行哈希处理并将其与第二个参数进行比较参数(

BCrypt.checkpw() takes a plain text password as it's first parameter, and will then hash it and compare it to the second parameter (docs); in your case you're giving it an already hashed password as it's first parameter, which it will then hash again hence it not matching.

这篇关于如何使用jBcrypt检查bcrypt密码?(将存储空间从Parse.com移至Firebase)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆