0% found this document useful (0 votes)
5 views3 pages

Practical 19106

The document outlines a practical assignment for creating a login form using Android XML and Java. It includes the XML layout for the login interface and the Java code for handling user input and checking credentials against a SQLite database. The application allows users to log in by validating their username and password against predefined entries in the database.

Uploaded by

babap9579
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Practical 19106

The document outlines a practical assignment for creating a login form using Android XML and Java. It includes the XML layout for the login interface and the Java code for handling user input and checking credentials against a SQLite database. The application allows users to log in by validating their username and password against predefined entries in the database.

Uploaded by

babap9579
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Yash Patel ER.

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;

public class MainActivity extends 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);

db = openOrCreateDatabase("student", Context.MODE_PRIVATE, null);


db.execSQL("create table if not exists login(user varchar(40), pass varchar(40))");

db.execSQL("insert into login values('abc','123')");


db.execSQL("insert into login values('bspp','123')");
db.execSQL("insert into login values('admin','admin')");
db.execSQL("insert into login values('guni','guni')");
}

public void check(View v) {


String user = t1.getText().toString();
String pass = t2.getText().toString();

Cursor result = db.rawQuery("SELECT * FROM login", null);


boolean found = false;

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

You might also like