php - Login via AsyncTask automatically fetching previously entered username,pwd -
i fetching username , password mysql using php...code goes alright when backpressed showing alert bar, want logout? loginactivity comes in picture. if user enters wrong username or password previous login data fetched. here php code
<?php include("db.php"); include("database.php"); $uname=$_request['username']; $upassword=$_request['password']; if($upassword!='' && $uname!=''){ $resultfac = selectsinglerow("facultylogin","password='$upassword' , username='$uname'",""); if($resultfac['facultyid']!=''){ $facid= $resultfac['facultyid']; $resultemp = selectsinglerow("tblfaculty","id='$facid'",""); if($resultfac['id']!=''){ $empid= $resultemp['employeeid']; $response["emp_id"]=$empid; $response["flag"]=1; echo json_encode($response); } } else{ $response["flag"]=0; echo "please enter correct user name password"; echo json_encode($response); } }else{ $response["flag"]=0; echo json_encode($response); echo "please enter both fields"; } ?>
and login activity
public class loginactivity extends activity { int flag; int empid; string username; string password; edittext edusername,edpassword; private progressdialog pdialog; jsonparser jparser = new jsonparser(); jsonarray jarray; arraylist<hashmap<string, string>> productslist; private static string url_faculty_login = "http://10.0.2.2/xyz/login_check.php"; private static final string tag_employee = "employee_id"; private static final string tag_pid = "pid"; private static final string tag_name = "name"; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.login); // settitlecolor(1); intent i=new intent(); edusername=(edittext) findviewbyid(r.id.edusername); edpassword=(edittext) findviewbyid(r.id.edpassword); string clear="clear"; } @override protected void onstop() { // todo auto-generated method stub super.onstop(); loginactivity.this.finish(); // loginactivity. } //@override protected void onpause() { // todo auto-generated method stub super.onpause(); loginactivity.this.finish(); } //onclick login.xml button public void signin(view view) { //call inner class if(edusername!=null && edpassword!=null ) { new loadallproducts().execute(); } else { toast.maketext(getapplicationcontext(), "enter both fields", toast.length_long); } } class loadallproducts extends asynctask<string, string, string> { private static final string emp_id = "emp_id"; public string doinbackground(string... args) { username=edusername.gettext().tostring(); password=edpassword.gettext().tostring(); list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("username", username)); params.add(new basicnamevaluepair("password", password)); jsonobject json = jparser.makehttprequest(url_faculty_login, "post", params); log.d("username n password: ", json.tostring()); try { flag=json.getint("flag"); log.d("flags",""+flag); } catch (jsonexception e) { e.printstacktrace(); } if(flag==1) { try { empid=json.getint(emp_id); } catch (jsonexception e) { e.printstacktrace(); } intent i=new intent(getapplicationcontext(),classactivity.class); i.setflags(intent.flag_activity_no_history); i.setflags(intent.flag_activity_clear_top); i.putextra("emp_id", ""+empid); log.d("empid",""+empid); startactivity(i); } if(flag==0) { intent i=new intent(getapplicationcontext(),invaliduploginactivity.class); startactivity(i); } return null; } } }
after
username=edusername.gettext().tostring(); password=edpassword.gettext().tostring(); edusername.settext(""); edpassword.settext("");
Comments
Post a Comment