Hi guys, sorry for registering and then immediately asking a question, but I'm at a loss. I'm trying to make a register/login function, with a local database (I know it's pointless to make a local login database function, but I'm a beginner and just want to make it work to prove to myself, before I make an actual working one)
I have a database helper that looks like ...
Now I have a 'Register Page' which the user can add their data to the database, that works fine. Now I just need to be able to read the database, and match a user's email and password with an entry within the database. Can anyone point me in the right direction? Or to any useful tutorials, because most of the ones I've came across aren't really that useful. I know I need to use cursors, but I just need a starting point really. Any help appreciated.
Thanks.
I have a database helper that looks like ...
Code:
public class DatabaseHelperClass extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "User.db";
public static final String TABLE_NAME = "user_Info";
public static final String COL_1 = "ID";
public static final String COL_2 = "NAME";
public static final String COL_3 = "EMAIL";
public static final String COL_4 = "PASSWORD";
public DatabaseHelperClass(Context context) { //Constructor
super(context, DATABASE_NAME, null, 1);
}
[USER=1021285]@override[/USER]
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,EMAIL TEXT,PASSWORD TEXT)");
//Auto incrementing PRIMARY KEY so it remains unique
}
[USER=1021285]@override[/USER]
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}//On edit
public boolean insertData(String name, String email, String password) {
SQLiteDatabase db = this.getWritableDatabase(); //Putting data into database
ContentValues contentValues = new ContentValues();
contentValues.put(COL_2, name);
contentValues.put(COL_3, email);
contentValues.put(COL_4, password);
long result = db.insert(TABLE_NAME, null, contentValues);
if (result == -1)
return false;
else
return true;
}
}
Now I have a 'Register Page' which the user can add their data to the database, that works fine. Now I just need to be able to read the database, and match a user's email and password with an entry within the database. Can anyone point me in the right direction? Or to any useful tutorials, because most of the ones I've came across aren't really that useful. I know I need to use cursors, but I just need a starting point really. Any help appreciated.
Thanks.
Last edited by a moderator: