database - Android login Error -
i making login page. in following code, userentered
, pswdentered
edittext
collecting user input. pass userentered
parameter in method getsingleentry
in database. want method check username in database , return corresponding password back. how method getsingleentry
look?
boolean diditwork = true; try { string userentered= user.gettext().tostring(); string pswdentered = pswd.gettext().tostring(); string storedpassword=logindb.getsingleentry(userentered); log.d("blahhhhhhhhh", storedpassword); if(pswdentered.equals(storedpassword)) { dialog id=new dialog(login.this); id.settitle("login"); textview tyv=new textview(login.this); tyv.settext("registration successful!"); id.setcontentview(tyv); } else { dialog id=new dialog(login.this); id.settitle("login"); textview tyv=new textview(login.this); tyv.settext("incorrect username or password!"); id.setcontentview(tyv); id.show(); } } /* catch(sqlexception ee) { diditwork=false; string error=ee.tostring(); dialog id=new dialog(login.this); id.settitle("sqlsqlsqlsql"); textview tyv=new textview(login.this); tyv.settext(error); id.setcontentview(tyv); id.show(); }*/ catch(exception e) { diditwork=false; string error=e.tostring(); dialog id=new dialog(login.this); id.settitle("login"); textview tyv=new textview(login.this); tyv.settext("retype password"+error ); id.setcontentview(tyv); id.show(); }
these database definitions.
public static final string key_rowid="_id"; public static final string key_name= "name"; public static final string key_username="username"; public static final string key_password="password"; public static final string key_mobile= "mobile"; public static final string key_email= "email"; private static final string database_name="logindb"; private static final string database_table="doctortable"; private static final int database_version=2;
public static string getsingleentry(string username) { log.d("db", username); cursor c; string[] columns= new string[]{key_rowid,key_name,key_username,key_password,key_mobile,key_email}; // string[] columns= new string[]{key_password}; c = db.rawquery("select password " + database_table + " username=?", new string[]{username}); // c=db.query("logindb", columns,key_username + "=" + username ,null, null, null, null); // c = db.rawquery("select password " + database_name + " username ='"+username+"'", null); // c= db.rawquery("select "+ key_password + "from" + database_name + "where" + key_username + "= ?", new string[] {username}); // c= db.rawquery("select password 'logindb' username ="+username, null); if(c!=null) { c.movetofirst(); string password= c.getstring(3); log.d("ruuuu",password); c.close(); return password; } return null; }
Comments
Post a Comment