sql - SQLite android login and register -
From the last question I asked, I'm still doing the same question. I do not know how to use the database (SQLite) 'sync' to log in or register with your application.
package log1.log2; Import android App Import android.content.Intent; Importroid.os.Bundle; Import android.view.View; Import android.view.View.OnClickListener; Import android.widget.Button; Import android.widget.EditText; Import android.widget.TextView; Enhances public class login activity {UserDB db = New UserDB (this); /** Called when the activity is first created. * / Private edit test name of ATU; Private editing text and password; Private button btnLogin; Private button btnRegister; Private textview LLRsult; Override public null on @reate (bundle saved instainstate) {super.naught (savedinstenstate); SetContentView (R.layout.main); // EditText and Button Reference etUsername = Go (EditText) findViewById (R.id.usernametxt); Find Atepassword = (edit text) VVBID (RID password); Find BTNLogin = (button) VVBIID (RID. BTNLogin); BtnRegister = (Button) findViewById (R.id.btnRegister); LblResult = (TextView) findViewById (R.id.msglbl); // Cursor C = (cursor) db.getAllTitles (); // button btnArrival = (button) findViewById (R.id.btnRegister); //btnArrival.setOnClickListener(this); // Set Click Listener btnRegister.setOnClickListener (New OnClickListener) {@Override Public Zero Click on (see V) {intent intention = new intent (login. This, Register.class); StartActivity;}}); BtnLogin.setOnClickListener (New OnClickListener () {@Override Public Zero onClick (see v) {db.open (); // log in string user name = etUsername.getText () toString () Check; string password = etPassword .getText () () .toString, if (username.equals ("user select username")) {if (password.equals ("user password = user name where user selects")) {intent Intent = new intent (Login.this, test .class); startActivity;} else {lblResult.setText ("wrong password");}} else {lblResult.setText ("The user name does not exist In please register .. ");} db.close ();}}); }}
Should I use "Statement" from "Select"? Or is there another way?
where you have
username.equals ("username" From the select user ")
You are actually checking that the user entered is actually the same object (which is not it). To authenticate against the user's local database, you want to try something else like this:
cursor c = db.rawQuery ("Choose user name from user where name ? And password = '?' ", New string [] {user name, password}); If (c.moveToFirst ()) {// at least one row was returned, then this should indicate success} Other {// authentication failed}
Where 'db' is The SQLiteDatabase object is working with you if you need some sort of security, so I will also have the password even before submitting it in the database!
Comments
Post a Comment