Lab Program 3
Lab Program 3
PART A
Program 3
Create a SIGN UP activity with Username and Password. Validation of password should happen
based on
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
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.
• Register the button for click event by calling setOnClickListener() method of View
class and pass the object of the class that implemented OnClickListener Interface.
activity_main.xml
<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
<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;
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
if(validatePassword(pwd)){
bundle.putString("username",uname);
bundle.putString("password",pwd);
intent.putExtras(bundle);
startActivity(intent);
}
else{
SCEM MOBILE APPLICATION DEVELOPMENT
}
});
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;
EditText username,password;
Button signInBtn;
int count=0;
@Override
username = findViewById(R.id.username);
password = findViewById(R.id.password);
signInBtn = findViewById(R.id.signin);
signInBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
else {
count++;
if (count >= 3) {
signInBtn.setEnabled(false);
} else {
}
});
}
}
SCEM MOBILE APPLICATION DEVELOPMENT
Sample Output