Java program to create a login page with username and password

Java program to create a login page with username and password. Make preparations to develop an application. Make the decision to create a login page. Before utilising the program, users must first register and login. They must establish a login page that is only accessible to registered users. Create a Java program to assist them in building a rudimentary model for their app by collecting registration information, storing it, and confirming the login procedure.

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String sp=" ";
System.out.println("Enter the username");
String name = sc.nextLine();
if((name.contains(sp)) || name.length()<4){
System.out.println("Invalid username");
return;
}
System.out.println("Enter the password");
String pass = sc.nextLine();
if((pass.contains(sp)) || pass.length()<8)
{
System.out.println("Invalid password");
return;
}
System.out.println(name+" you are registered successfully");
System.out.println("Enter the username");
String lname = sc.nextLine();
System.out.println("Enter the password");
String lpass = sc.nextLine();
if(name.equals(lname) && pass.equals(lpass)){
System.out.println("Welcome "+lname+" you have logged-in successfully");
}
else{
System.out.println("Username or password mismatch");
}
}
}

 

Output:

Enter the username
raghu
Enter the password
456
Invalid password