java.net.PasswordAuthentication Class in Java Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report PasswordAuthentication class is provided by package java.net for implementing networking applications, and it is used in those cases when it is required to hold the data that will be used by the Authenticator. It holds the username and password. Syntax of its constructors : PasswordAuthentication(String userName, char[] password)This will create new PasswordAuthentication object for the given username and password. The given user password is cloned before it is stored in the new PasswordAuthentication object. Method Return TypegetUserName()Returns the username.getPassword()Returns the user password.Method details: getUserName() : This will give the username and is return a string value.getPassword() : This will return user password and return char array.Methods it inherited from class java.lang.Object : equals()toString()hashCode()clone()getClass()finalize()notify()notifyAll() Java // Java Program to illustrate the // java.net.PasswordAuthentication // Class import java.io.*; import java.net.PasswordAuthentication; class GFG { public static void main(String args[]) { GFG acc = new GFG(); acc.proceed(); } private void proceed() { // Initializing the user name String userName = "Geek"; // Initializing the password - This is a char // array since the PasswordAuthentication // supports this argument char[] password = { 'g', 'e', 'e', 'k', 'g', 'o', 'r', 'g', 'e', 'e', 'k', 's' }; PasswordAuthentication passwordAuthentication = new PasswordAuthentication(userName, password); System.out.println( "UserName: " + passwordAuthentication.getUserName()); // The below getPassword actually returns the // reference to the password as per the Java API // documentation. System.out.println( "Password: " + passwordAuthentication.getPassword()); // You can get the password in normal string System.out.println( "Password: " + String.copyValueOf( passwordAuthentication.getPassword())); } } OutputUserName: Geek Password: [C@4e50df2e Password: geekgorgeeks Create Quiz Comment M maheswaripiyush9 Follow 0 Improve M maheswaripiyush9 Follow 0 Improve Article Tags : Java Java-net-package Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like