Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. package com.example.bruna.appvalid1;
  2.  
  3. import android.content.ContentValues;
  4. import android.content.Context;
  5. import android.database.Cursor;
  6. import android.database.SQLException;
  7. import android.database.sqlite.SQLiteDatabase;
  8. import android.database.sqlite.SQLiteOpenHelper;
  9.  
  10. /**
  11. * Created by bruna on 24/08/2016.
  12. */
  13. public class DBAdapter {
  14.  
  15. private static final String DATABASE_TABLE = "membersdb";
  16. public static final String KEY_ROW_ID = "_id";
  17. public static final String KEY_USERNAME = "username";
  18. public static final String KEY_PASSWORD = "password";
  19.  
  20. SQLiteDatabase mDb;
  21. Context mCtx;
  22. DBHelper mDbHelper;
  23.  
  24. public DBAdapter(Context context){
  25.  
  26. this.mCtx=context;
  27. }
  28.  
  29. public DBAdapter openDataBase() throws SQLException{
  30. mDbHelper = new DBHelper(mCtx);
  31. mDb = mDbHelper.getWritableDatabase();
  32. return this;
  33. }
  34.  
  35. public void close(){
  36. mDbHelper.close();
  37. }
  38.  
  39. public long register(String user, String pw){
  40. ContentValues initialValues = new ContentValues();
  41. initialValues.put(KEY_USERNAME, user);
  42. initialValues.put(KEY_PASSWORD, pw);
  43.  
  44. return mDb.insert(DATABASE_TABLE, null, initialValues);
  45. }
  46.  
  47. public boolean Login(String username, String password) throws SQLException{
  48. Cursor mCursor = mDb.rawQuery("SELECT * FROM " + DATABASE_TABLE + " WHERE username = ? AND password = ?", new String[]{username, password});
  49. if(mCursor!=null) {
  50. if (mCursor.getCount() > 0) {
  51. return true;
  52. }
  53. }
  54. return false;}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement