我有登录和重置密码活动。当我输入新的更新密码并尝试再次登录时,我无法使用新密码。使用旧密码登录可以正常工作。基本上,密码字段不会被更新/覆盖。
logcat中没有错误。只是密码没有更新。
请帮助我,因为我是Android开发的新手。
更新代码(DataRegister是具有GET和SET功能的类):
public int updatePassword(DataRegister dataregister) {
db = dbHelper.getWritableDatabase();
ContentValues updated = new ContentValues();
updated.put("PASSWORD", dataregister.getPASSWORD());
return db.update(DataRegister.TABLE, updated, "EMAIL=?" , new String[] {dataregister.getEMAIL()});
}
检索代码:
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
}
登录代码:
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();
}
}
});
重置密码代码:
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);
答案 0 :(得分:-1)
我没有足够的评论声誉,所以我会把我的建议写成答案......对不起
我认为这对你有帮助
在你的getPass方法
中if (cursor != null)
cursor.moveToFirst()
pass = cursor.getString(cursor.getColumnIndex("PASSWORD"));
cursor.close();