Enter username and password as input strings. After that we match both strings against given username and password. If it matches then Authentication is successfull or else Authentication fails.
Here is the source code of the Java Program to Illustrate how User Authentication is Done. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class User_Authentication
public static void main(String args)
String username, password;
Scanner s = new Scanner(System.in);
username = s.nextLine();
password = s.nextLine();
if(username.equals("user") && password.equals("user"))
$ javac User_Authentication.java $ java User_Authentication Enter username:user Enter password:user Authentication Successful Enter username:abcd Enter password:1234 Authentication Failed
Sanfoundry Global Education & Learning Series – 1000 Java Programs.