Practical 19106
Practical 19106
No-22171371106
Practical-19
Aim :- Create login form and check login information with database table.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Username"
android:inputType="text"
android:textSize="40dp" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Password"
android:inputType="textPassword"
android:textSize="40dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="LOGIN"
android:textSize="40dp"
android:onClick="check" />
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RESULT"
android:textSize="40dp" />
</LinearLayout>
MainActivity.java
package com.example.p19;
Yash Patel ER.No-22171371106
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
SQLiteDatabase db;
TextView tv;
EditText t1, t2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
t1 = findViewById(R.id.username);
t2 = findViewById(R.id.password);
tv = findViewById(R.id.tv);
while (result.moveToNext()) {
if (result.getString(0).equals(user) && result.getString(1).equals(pass)) {
tv.setText("Login Correct");
found = true;
break;
}
}
Yash Patel ER.No-22171371106
if (!found) {
tv.setText("Login Fail");
}
result.close();
}
}
OUTPUT