使用BCrypt

时间:2016-04-17 16:34:19

标签: java sqlite

当我的用户登录到应用程序时,我需要将其密码的文本版本与数据库中的散列值进行比较。但是我真的很挣扎。

任何人都可以帮助我吗?

public void onButtonClick(View v)

{
    if (v.getId() == R.id.Blogin) {

        EditText a = (EditText) findViewById(R.id.TFusername);
        String str = a.getText().toString();
        EditText b = (EditText) findViewById(R.id.TFpassword);
        String pass = b.getText().toString();


        String login = helper.searchPass(str);

        **// if username is = to the password in the database
        if (pass.equals(login)

                //method to check password hashes
                // BCrypt.checkpw(*user input plain text*, *previous hash from db*
                && BCrypt.checkpw( //i dont know what to put here ) ) {**

            Intent i = new Intent(MainActivity.this, RegForensics.class);
            i.putExtra("Username", str);
            startActivity(i);


            Login l = new Login();
            l.setUserlog(str);

            helper.insertLogin(l);


        } else {
            Toast temp = Toast.makeText(MainActivity.this, "Username and password don't match!", Toast.LENGTH_SHORT);
            temp.show();


        }

1 个答案:

答案 0 :(得分:1)

根据评论,有两个参数,用户提供的密码和来自数据库的散列密码。

BCrypt.checkpw将对密码进行哈希处理并与之前的哈希密码进行比较。

请参阅BCrypt documentation

注意:散列密码的第一部分包含有关散列的元数据。

相关问题