Wednesday, December 10, 2025
HomeLanguagesJavaJava Program to Demonstrate How User Authentication is Done

Java Program to Demonstrate How User Authentication is Done

Authentication is the process of verifying the identity of users or information. User authentication is the process of verifying the identity of the user when that user logs in to a computer system. The main objective of authentication is to allow authorized users to access the computer and to deny access to unauthorized users.

Example

Default Assumption: User name = Geeks For Geeks , Password = Geeks For Geeks

Input: User name = Geeks For Geeks, Password = Geeks For Geeks
Output: Authentication Successful

Input: User name = Geeks For Geeks, Password = Hello world
Output: User name/ Password not matching

Approach

  1. Take username and password as string input from the user.
  2. Check if the username matches the password or not.
  3. If it matches then welcome the user.
  4. Else display an appropriate message.

Below is the implementation of the above approach

Java




// Java program to check the authentication of the user
  
// Importing the modules
import java.util.*;
  
// Gfg Class
public class Gfg 
{
    // Main CLass
    public static void main(String args[])
    {
        // Declaring the username and password
        String user_name = "Geeks For Geeks";
        String password = "Geeks For Geeks";
          
        // Checking the validity of the input
        if(user_name.equals("Geeks For Geeks") && password.equals("Geeks For Geeks"))
        {
            // Printing Output
            System.out.println("Authentication Successful");
        }
        else
        {
            // Printing Output
            System.out.println("User name/ Password not matching");
        }
    }
}


Output

Authentication Successful

 

RELATED ARTICLES

Most Popular

Dominic
32440 POSTS0 COMMENTS
Milvus
104 POSTS0 COMMENTS
Nango Kala
6810 POSTS0 COMMENTS
Nicole Veronica
11950 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12022 POSTS0 COMMENTS
Shaida Kate Naidoo
6942 POSTS0 COMMENTS
Ted Musemwa
7193 POSTS0 COMMENTS
Thapelo Manthata
6889 POSTS0 COMMENTS
Umr Jansen
6880 POSTS0 COMMENTS