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

Exp 28

The document describes creating a login form with XML layout and Java code. It includes validations for empty fields, minimum password length, and incorrect login attempts before displaying success or failure messages.

Uploaded by

HARSH MAGHNANI
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)
60 views3 pages

Exp 28

The document describes creating a login form with XML layout and Java code. It includes validations for empty fields, minimum password length, and incorrect login attempts before displaying success or failure messages.

Uploaded by

HARSH MAGHNANI
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

Exp28: Write a program to create the login form with necessary validations like length of

username and password, empty text fields, count of unsuccessful login attempts. Display the
login successful/Unsuccessful toast message.
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<EditText
android:id="@+id/User_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password:"
android:inputType="textPassword"
android:layout_below="@+id/User_email"
android:layout_marginTop="50dp"
android:padding="10dp"/>

<TextView
android:id="@+id/User_Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:textSize="40dp"
android:text="Login Form"/>

<Button
android:id="@+id/User_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/User_password"
android:layout_marginTop="50dp"
android:text="Login"/>
<EditText
android:id="@+id/User_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/User_Text"
android:layout_marginTop="50dp"
android:hint="Email:"
android:padding="10dp"
android:inputType="textEmailAddress"/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="~Developed By [Link] (Roll no:06)"
android:textColor="#0000FF"
android:textSize="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="35dp"
android:layout_marginEnd="35dp" />

</[Link]>
[Link]:
package [Link].exp28;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
Button login;
EditText username,pass;
public String user,psd;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

login = findViewById([Link].User_login);
[Link](new [Link]() {
@Override
public void onClick(View v) {
check();
}
});
username = findViewById([Link].User_email);
pass = findViewById([Link].User_password);
}
public void check(){
user = [Link]().toString().trim();
psd = [Link]().toString().trim();

if([Link]()) {
[Link]("Enter an e-mail");
[Link]();
return;
}
if(!Patterns.EMAIL_ADDRESS.matcher(user).matches()){
[Link]("Enter an e-mail");
[Link]();
return;
}
if([Link]()) {
[Link]("Enter a password ");
[Link]();
return;
}
if([Link]()<6){
[Link]("Minimum length is 6 characters");
[Link]();
return;
}
if([Link]("[Link]@[Link]") &&
[Link]("harsh123")) {
[Link]([Link],"Welcome User",
Toast.LENGTH_LONG).show();
Intent in = new Intent([Link],[Link]);
startActivity(in);
}
else{
[Link](this,"Wrong email or
password",Toast.LENGTH_LONG).show();
}}}
[Link]:
package [Link].exp28;
import [Link];
import [Link];
import [Link];

public class NewActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link]([Link],"Welcome to
College",Toast.LENGTH_LONG).show();
}
}
Output:-

You might also like