Java Code Example: simple login

The following program represents a simple login process. The user is prompted to enter his username and password. Subsequently, the user entries are checked. If they match the stored data, the user receives the message “successfully logged in”.

import java.util.Scanner;

public class LoginExample {
    static boolean checkUserInput(String username, String password) {
        String pw = "123456", name = "user";

        if (username.equals(name) && password.equals(pw)) {
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String username, password;

        System.out.println("Enter username: ");
        username = scan.next().toLowerCase();
        System.out.println("Enter password: ");
        password = scan.next().toLowerCase();

        if (checkUserInput(username, password)) {
            System.out.print("Successfully logged in");
        } else {
            System.out.print("Wrong username or password");
        }
    }
}
Output first run
Enter username: 
user
Enter password: 
123456
Successfully logged in
Output second run
Enter username: 
jason
Enter password: 
3453
Wrong username or password