I've been trying to update the password for a specific user on my android app, but it just won't work. It gives me a "Password Updated Successfully" message but in the SQLite database, it doesn't change at all. I'm not sure what's wrong, my code is below.
//Database.java
public long updatePassword(String password, String email) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("password", password);
return db.update("users", values, email+ "= ?" , new String[]{email});
//db.close();
}
//ConfirmPassword.java below
resetpass.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String val1 = pass1.getText().toString();
String val2 = pass2.getText().toString();
if (val1.isEmpty() && val2.isEmpty()) {
Toast.makeText(getApplicationContext(), "Fields are Empty", Toast.LENGTH_SHORT).show();
return;
}
if (!val1.contentEquals(val2)) {
Toast.makeText(getApplicationContext(), "Password doesn't match. Try again!",
Toast.LENGTH_SHORT).show();
pass1.setText("");
pass2.setText("");
return;
}
else {
//db.open();
db.updatePassword(val1, email); //email here throws an error since there is no field and email declaration in this file
db.close();
Toast.makeText(getApplicationContext(), "Password Updated Successfully",
Toast.LENGTH_SHORT).show();
openLogin();
}
}
});