dimanche 17 avril 2016

Comparing hashed password from SQLite database to user input using BCrypt

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();


        }

Aucun commentaire:

Enregistrer un commentaire