I have a login and reset password activity. When I enter the new updated password and try to login again, I cannot do so with the new password. Logging in with the old password works fine. Basically, the password field is not getting updated/overwritten.
There is no error in the logcat. Just that the password is not updated.
Please help as I am new to android development.
Code for update( DataRegister is the class with GET AND SET functions):
public int updatePassword(String email, String paa) {
db = dbHelper.getWritableDatabase();
ContentValues updated = new ContentValues();
updated.put("PASSWORD", paa);
// db.execSQL(" UPDATE " + DataRegister.TABLE +
// " SET PASSWORD = '" + password + "'" + " WHERE EMAIL = ? " , new String[]{email});
return db.update(DataRegister.TABLE, updated, "EMAIL=?" , new String[]{email});
}
Code for retrieval:
public String getPass(DataRegister dataRegister) {
db = dbHelper.getWritableDatabase();
Cursor cursor = db.query(DataRegister.TABLE, null, "EMAIL=?",
new String[]{dataRegister.getEMAIL()}, null, null, null, null);
if (cursor != null && cursor.moveToFirst())
{
pass = cursor.getString(cursor.getColumnIndex("PASSWORD"));
cursor.close();
}
return pass;
// return contact
}
Code for Login:
String email = editTextUserName.getText().toString();
dataRegister.setEMAIL(email);
String password = editTextPassword.getText().toString();
dataRegister.setPASSWORD(password);
String storedPassword = loginDataBaseAdapter.getSinlgeEntry(dataRegister);
Toast.makeText(Login.this, storedPassword,Toast.LENGTH_LONG).show();
Boolean a=loginDataBaseAdapter.isExist(dataRegister.getEMAIL());
validation = getSharedPreferences("myShaPreferences", Context.MODE_PRIVATE);
if (password.equals(storedPassword)) {
Toast.makeText(Login.this,
"Congrats: Login Successful", Toast.LENGTH_LONG)
.show();
}
else {
Toast.makeText(Login.this,
"User Name or Password does not match",
Toast.LENGTH_LONG).show();
}
}
});
Code for reset password:
public class ResetPassword extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reset_password);
email = (EditText) findViewById(R.id.em2);
dataRegister=new DataRegister();
loginDataBaseAdapter = new DatabaseAdapter(this);
loginDataBaseAdapter = loginDataBaseAdapter.open();
pass = (EditText) findViewById(R.id.text12);
conpass = (EditText) findViewById(R.id.text13);
email1 = email.getText().toString();
dataRegister.setEMAIL(email1);
pass1 = pass.getText().toString();
conpass1 = conpass.getText().toString();
dataRegister.setPASSWORD(conpass1);
Button btnReset = (Button) findViewById(R.id.btnReset);
btnReset.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (pass1.equals(conpass1)) {
loginDataBaseAdapter.updatePassword(email1,pass1);
String newpass = loginDataBaseAdapter.getPass(dataRegister);
Toast.makeText(ResetPassword.this, newpass, Toast.LENGTH_LONG).show();
Intent intent = new Intent(ResetPassword.this, Login.class);
startActivity(intent);
finish();
}
else {
Toast.makeText(ResetPassword.this,
"Password does not match",
Toast.LENGTH_LONG).show();
}
}
});
Aucun commentaire:
Enregistrer un commentaire