Login page in android using database
<p>I'm new to Android and Java. I'm doing a login page program. In that program I don't know how to do user authentication or validation process. </p>

<p>please help me </p>

<pre><code>public class demo extends Activity implements OnClickListener {
 /** Called when the activity is first created. */
 EditText txtbox1, txtbox2;
 private DataHelper dh;
 Button button2, button1;
 String name1, name2, name;
 String DB_PATH, DATABASE_NAME;
 String unames;
 TextView tv;
 private static final String TABLE_NAME = "table1";
  private DataHelper db;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  txtbox1 = (EditText) findViewById(R.id.EditText01);
  txtbox2 = (EditText) findViewById(R.id.EditText02);
  button2 = (Button) findViewById(R.id.Button02);
  button1 = (Button) findViewById(R.id.Button01);
  button1.setOnClickListener(this);
  button2.setOnClickListener(this);
  tv = (TextView) this.findViewById(R.id.mywidget);  
        tv.setSelected(true); 
 }

@Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  int i = v.getId();
  {
   if (i == R.id.Button01) {
    name1 = txtbox1.getText().toString();
    name2 = txtbox2.getText().toString();

    System.out.println("txtbox1" + txtbox1);
    System.out.println("name1" + name1);
    System.out.println("name2" + name2);

    StringBuilder sb = new StringBuilder();
    sb.append("Insert Employee Details:\n");
      dh = new DataHelper(this);
          dh.deleteAll();
    dh.insert(name1);
    dh.insert(name2);

    Toast.makeText(getApplicationContext(), name1,
      Toast.LENGTH_LONG).show();
    List&lt;String&gt; names = this.dh.selectAll();
    /* sb.append("Names in database:\n"); */
    for (String name : names) {
     sb.append(name + "\n");
     System.out.println("name=" + names);

     Log.d("EXAMPLE", "names size - " + names.size());
    }

   }
  }
  if (i == R.id.Button02)
  System.out.println("ok");
  System.out.println("name=" + unames);

/*     GetValue();
*/
  {
   if (name1.equals(unames)) {
    System.out.println("ok1");
    Toast.makeText(getApplicationContext(), name1,
      Toast.LENGTH_LONG).show();
   } else {
    System.out.println("no");
    /*
     * Toast.makeText(getApplicationContext(),no ,
     * Toast.LENGTH_LONG).show();
     */

   }

  }

 }
}
</code></pre>

<p>database part</p>

<pre><code>public class DataHelper {

 private static final String DATABASE_NAME = "example1rrrr.db";
 private static final int DATABASE_VERSION = 1;
 private static final String TABLE_NAME = "table1";
 private static final String name = "name";
 private static final String password = "password";
 private static final String KEY_ROWID = "rowid";
 private Context context;
 private static SQLiteDatabase db;


 private SQLiteStatement insertStmt;
 private static final String INSERT = "insert into " + TABLE_NAME
   + "(name) values (?)";

 public DataHelper(Context context) {
  this.context = context;
  OpenHelper openHelper = new OpenHelper(this.context);
  this.db = openHelper.getWritableDatabase();
  this.insertStmt = this.db.compileStatement(INSERT);
 }

 public long insert(String name) {
  this.insertStmt.bindString(1, name);
  return this.insertStmt.executeInsert();
 }


public void deleteAll() {
  this.db.delete(TABLE_NAME, null, null);
 }

 public List&lt;String&gt; selectAll() {
  List&lt;String&gt; list = new ArrayList&lt;String&gt;();
  Cursor cursor = this.db.query(TABLE_NAME, new String[] { "name" },
    null, null, null, null, "name asc");
  if (cursor.moveToFirst()) {
   do {
    list.add(cursor.getString(0));
   } while (cursor.moveToNext());
  }
  if (cursor != null &amp;&amp; !cursor.isClosed()) {
   cursor.close();
  }
  return list;
 }

 private static class OpenHelper extends SQLiteOpenHelper {

  OpenHelper(Context context) {
   super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
   db.execSQL("CREATE TABLE " + TABLE_NAME
     + "(id INTEGER PRIMARY KEY, name TEXT)");
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
   Log.w("Example",
     "Upgrading database, this will drop tables and recreate.");
   db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
   onCreate(db);

  }
</code></pre>
