database - Update sqlite not working on android -
i have login , reset password activity. when enter new updated password , try login again, cannot new password. logging in old password works fine. basically, password field not getting updated/overwritten.
there no error in logcat. password not updated.
please new android development.
code update( dataregister class , set functions):
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()}); }
code 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 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 not match", toast.length_long).show(); } } });
code 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);
i don't have enough reputation comment write suggestion answer...sorry that
i think u
in getpass method
if (cursor != null) cursor.movetofirst() pass = cursor.getstring(cursor.getcolumnindex("password")); cursor.close();
Comments
Post a Comment