-
Notifications
You must be signed in to change notification settings - Fork 1
/
Database.java
51 lines (44 loc) · 1.58 KB
/
Database.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.example.loginpage;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
public class Database extends SQLiteOpenHelper {
public Database(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
String qry1 = "create table users(username text, email text, password text)";
sqLiteDatabase.execSQL(qry1);
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
public void register(String username, String email, String password)
{
ContentValues cv = new ContentValues();
cv.put("username",username);
cv.put("email",email);
cv.put("password",password);
SQLiteDatabase db = getWritableDatabase();
db.insert("users",null,cv);
db.close();
}
public int login(String username, String password)
{
int result = 0;
String str[] = new String[2];
str[0] = username;
str[1] = password;
SQLiteDatabase db = getReadableDatabase();
Cursor c = db.rawQuery("select * from users where username=? and password=?",str);
if(c.moveToFirst())
{
result=1;
}
return result;
}
}