Android remote connection to Mysql DB through php - Login authentication -


i developing small application , authentication needed. i'm trying develop connecting mysql db through php.

add uname/pw --> loging --> send php --> check db --> ok sends android --> authenticated. / error sends re loging.

i have developed far, think how should i'm not sure since i'm new cording.
please kind enough me cording. thank you.

public class loging extends activity{      textview txt;     edittext uname,pwd;      @override     protected void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);          setcontentview(r.layout.loging);         button b = (button)findviewbyid(r.id.log);         uname = (edittext)findviewbyid(r.id.uname);         pwd = (edittext)findviewbyid(r.id.pwd);          b.setonclicklistener(new view.onclicklistener() {              public void onclick(view arg0) {                 // todo auto-generated method stub                  arraylist<namevaluepair> namevaluepairs = new arraylist<namevaluepair>();                      namevaluepairs.add(new basicnamevaluepair("name", uname.gettext().tostring()));                     namevaluepairs.add(new basicnamevaluepair("pass", pwd.gettext().tostring()));                      try                      {                      httpclient httpclient = new defaulthttpclient();                      httppost httppost = new httppost("http://www.helloworld.com/report.php");                      httppost.setentity(new urlencodedformentity(namevaluepairs));                      httpresponse response = httpclient.execute(httppost);                      httpentity entity = response.getentity();                      inputstream = entity.getcontent();                     }                     catch(exception e)                     {                             log.e("log_tag","error in http connection"+e.tostring());                     }                }         });     } } 

public class loging extends activity{      textview txt;     edittext uname,pwd;     final loging login = this;      @override     protected void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);          setcontentview(r.layout.loging);         button loging = (button)findviewbyid(r.id.log);         button adduser = (button)findviewbyid(r.id.adduser);         uname = (edittext)findviewbyid(r.id.uname);         pwd = (edittext)findviewbyid(r.id.pwd);           loging.setonclicklistener(new view.onclicklistener() {               public void onclick(view arg0) {                 // todo auto-generated method stub                   // create new httpclient , post header                 httpclient httpclient = new defaulthttpclient();                  /* login.php returns true if username , password equal saranga */                 httppost httppost = new httppost("http://www.xoxoxoxox.com/login.php");                  try {                     // add user name , password                  edittext uname = (edittext)findviewbyid(r.id.uname);                  string username = uname.gettext().tostring();                   edittext pword = (edittext)findviewbyid(r.id.pwd);                  string password = pword.gettext().tostring();                      list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(2);                     namevaluepairs.add(new basicnamevaluepair("username", username));                     namevaluepairs.add(new basicnamevaluepair("password", password));                     httppost.setentity(new urlencodedformentity(namevaluepairs));                      // execute http post request                     log.w("sencide", "execute http post request");                     httpresponse response = httpclient.execute(httppost);                      string str = inputstreamtostring(response.getentity().getcontent()).tostring();                     log.w("sencide", str);                      if(str.tostring().equalsignorecase("true"))                     {                      log.w("sencide", "true");                      //result.settext("login successful");                          intent in = new intent();                         in.setclass(login, mappingactivity.class);                                 startactivity(in);                     }else                     {                      log.w("sencide", "false");                      alertdialog alertdialog = new alertdialog.builder(loging.this).create();                         alertdialog.settitle("credentials missing");                         alertdialog.setmessage("please add username , password");                         alertdialog.setbutton("ok", new dialoginterface.onclicklistener() {                            public void onclick(dialoginterface dialog, int which) {                               // here can add functions                                intent = new intent();                                 i.setclass(login, mappingactivity.class);                                         startactivity(i);                            }                         });                         alertdialog.show();                                 }                  } catch (clientprotocolexception e) {                  e.printstacktrace();                 } catch (ioexception e) {                  e.printstacktrace();                 }               }              private object inputstreamtostring(inputstream is) {                 // todo auto-generated method stub                 string line = "";                  stringbuilder total = new stringbuilder();                  // wrap bufferedreader around inputstream                  bufferedreader rd = new bufferedreader(new inputstreamreader(is));                  // read response until end                  try {                   while ((line = rd.readline()) != null) {                      total.append(line);                    }                  } catch (ioexception e) {                   e.printstacktrace();                  }                  // return full string                  return total;             }         });          adduser.setonclicklistener(new view.onclicklistener() {              public void onclick(view v) {                 // todo auto-generated method stub                 intent in = new intent();                 in.setclass(login, adduser.class);                         startactivity(in);             }         });         }  } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -