0

When my user logs in to the application I need their text version of the password to compare with the hashed value in the database. However i am really struggling.

Can anyone help me?

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 Answer 1

1

Per the comment there are two parameters, the user supplied password and the hashed password from the DB.

BCrypt.checkpw will hash the password and compare to the previously hashed password.

See BCrypt documentation.

Note: the first part of the hashed password contains metadata about the hashing.

Sign up to request clarification or add additional context in comments.

1 Comment

I understand that but I don't, know what to put there. I know it needs to be BCrypt.checkpw(pass, **) but I can't figure out how to pull the corresponding hashed passwords.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.