0% found this document useful (0 votes)
14 views14 pages

Lab Program 3

The document describes creating a mobile application with sign up and login functionality. It includes instructions to create sign up and login activities with username and password fields. The sign up activity should validate the password based on rules for including uppercase, lowercase, numbers, and special characters. On successful sign up, it should proceed to the login activity. The login activity should match the username and password and navigate to a success message, otherwise display an error. It is limited to two attempts before disabling the button.

Uploaded by

KUMAR RISHAV
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)
14 views14 pages

Lab Program 3

The document describes creating a mobile application with sign up and login functionality. It includes instructions to create sign up and login activities with username and password fields. The sign up activity should validate the password based on rules for including uppercase, lowercase, numbers, and special characters. On successful sign up, it should proceed to the login activity. The login activity should match the username and password and navigate to a success message, otherwise display an error. It is limited to two attempts before disabling the button.

Uploaded by

KUMAR RISHAV
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/ 14

SCEM MOBILE APPLICATION DEVELOPMENT

PART A
Program 3
Create a SIGN UP activity with Username and Password. Validation of password should happen
based on

the following rules:

• Password should contain uppercase and lowercase letters.

• Password should contain letters and numbers.

• Password should contain special characters.

• Minimum length of the password (the default value is 8).

On successful SIGN UP proceed to the next Login activity. Here the user should SIGN IN using
the Username and Password created during signup activity. If the Username and Password are
matched then navigate to the next activity which displays a message saying “Successful Login”
or else display a toast message saying “Login Failed”. The user is given only two attempts and
after that display a toast message saying “Failed Login Attempts” and disable the SIGN IN
button. Use Bundle to transfer information from one activity to another.
SCEM MOBILE APPLICATION DEVELOPMENT

Solution

1. Create a New Android Project with Empty Activity.

2. Open activity_main.xml file from res→ layout folder, check/add Constraint Layout as the

root view.

3. Create Signup Layout using Drag and Drop framework design the layout.

4. Create One more Empty Activity sign_in using Android Studio Create Activity

Flow.

5. Open activity_sign_in.xml file from res→layout folder, check/add Constraint Layout as the

root view.

6. Create Login Layout using Drag and Drop framework.

7. Add Listeners to Button Click Event:

• Create a class which implements OnClickListener interface.

• Override onClick() method of OnClickListener Interface.

• Register the button for click event by calling setOnClickListener() method of View

class and pass the object of the class that implemented OnClickListener Interface.

8. Use Regular Expression"^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[@$!])[A-Za-z\\d@$!]{8,}$” to


validate the password.
SCEM MOBILE APPLICATION DEVELOPMENT

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<EditText

android:id="@+id/username"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:ems="10"

android:inputType="textPersonName"

android:hint="UserName"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.497"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.316" />
SCEM MOBILE APPLICATION DEVELOPMENT

<EditText

android:id="@+id/password"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:ems="10"

android:inputType="textPassword"

android:hint="Password"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.497"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

<Button

android:id="@+id/signup"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Sign Up"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"
SCEM MOBILE APPLICATION DEVELOPMENT

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.717" />

<TextView

android:id="@+id/textView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Sign Up Page"

android:textSize="30dp"

android:textColor="@color/white"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.498"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.11" />

</androidx.constraintlayout.widget.ConstraintLayout>
SCEM MOBILE APPLICATION DEVELOPMENT

activity_sign_in.xml

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout
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:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".SignIn">

<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Sign In Page"

android:textSize="30dp"

android:textColor="@color/white"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.498"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.143" />
SCEM MOBILE APPLICATION DEVELOPMENT

<EditText

android:id="@+id/username"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:ems="10"

android:inputType="textPersonName"

android:hint="UserName"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.497"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.38" />

<EditText

android:id="@+id/password"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:ems="10"

android:inputType="textPassword"

android:hint="Password"
SCEM MOBILE APPLICATION DEVELOPMENT

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.497"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.581" />

<Button

android:id="@+id/signin"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Sign In"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.8" />

</androidx.constraintlayout.widget.ConstraintLayout>
SCEM MOBILE APPLICATION DEVELOPMENT

MainActivity.java

package com.example.login;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;

import android.service.autofill.FieldClassification;
import android.view.View;
import android.widget.Button;

import android.widget.EditText;
import android.widget.Toast;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class MainActivity extends AppCompatActivity {

EditText username,password;
Button signUpBtn;

String regularExpr="^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[@$!])[A-Za-z\\d@$!]{8,}$";

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SCEM MOBILE APPLICATION DEVELOPMENT

username = findViewById(R.id.username);
password = findViewById(R.id.password);

signUpBtn = findViewById(R.id.signup);

signUpBtn.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) {


String uname = username.getText().toString();
String pwd = password.getText().toString();

if(validatePassword(pwd)){

Bundle bundle = new Bundle();

bundle.putString("username",uname);

bundle.putString("password",pwd);

Intent intent = new Intent(MainActivity.this,SignIn.class);

intent.putExtras(bundle);

startActivity(intent);

}
else{
SCEM MOBILE APPLICATION DEVELOPMENT

Toast.makeText(MainActivity.this, "Invaild Password", Toast.LENGTH_SHORT).show();

}
});

public boolean validatePassword(String pwd){


Pattern pattern = Pattern.compile(regularExpr);
Matcher matcher = pattern.matcher(pwd);

return matcher.matches();

}
SignIn.java

package com.example.login;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;
import android.widget.Button;

import android.widget.EditText;
import android.widget.Toast;

public class SignIn extends AppCompatActivity {


SCEM MOBILE APPLICATION DEVELOPMENT

EditText username,password;
Button signInBtn;

int count=0;

@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);

username = findViewById(R.id.username);

password = findViewById(R.id.password);
signInBtn = findViewById(R.id.signin);

Bundle bundle = getIntent().getExtras();

String uname = bundle.getString("username");

String pwd = bundle.getString("password");

signInBtn.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

String user = username.getText().toString();


String pass = password.getText().toString();

if(user.equals(uname) && pass.equals(pwd)){


SCEM MOBILE APPLICATION DEVELOPMENT

Toast.makeText(SignIn.this, "Success", Toast.LENGTH_SHORT).show();

}
else {

count++;
if (count >= 3) {

signInBtn.setEnabled(false);
} else {

Toast.makeText(SignIn.this, "Failed", Toast.LENGTH_SHORT).show();


}
}

}
});

}
}
SCEM MOBILE APPLICATION DEVELOPMENT

Sample Output

You might also like