Understandng java.net.PasswordAuthentication

PasswordAuthentication holds the data that will be used by the Authenticator. The username and password are stored in the PasswordAuthentication object. The methods getUserName() and getPassword() are made available that return the userName and password respectively.

import java.net.PasswordAuthentication;

public class UnderstandingPasswordAuthentication
{
   public static void main(String args[])
   {
      UnderstandingPasswordAuthentication understandingPasswordAuthentication = new UnderstandingPasswordAuthentication();
      understandingPasswordAuthentication.proceed();
   }
   
   private void proceed()
   {
      //Initializing the user name
      String userName = “devUser”;
      //Initializing the password – This is a char array since the PasswordAuthentication supports this argument
      char[] password = {‘d’,’e’,’v’,’U’,’s’,’e’,’r’};
      
      PasswordAuthentication passwordAuthentication = new PasswordAuthentication(userName, password);
      System.out.println(“Details being retrieved from PasswordAuthentication object post initializing”);
      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()));
   }
}

/*

Expected output:

[[email protected]]# java UnderstandingPasswordAuthentication
Details being retrieved from PasswordAuthentication object post initializing
UserName: devUser
Password: [[email protected]
Password: devUser

*/

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

Windows Logging is one of the vital aspects of any Windows system administration. However, it is mostly overlooked until the system develops a problem. This is because logs contain important information needed to troubleshoot and resolve system issues.

The Fundamentals of Windows Logging

Windows Logging is one of the vital aspects of any Windows system administration. However, it is mostly overlooked until the system develops a problem. This is because logs contain important information needed to troubleshoot and resolve system issues. Without it, tech experts might find it difficult to track a computer’s

Interstitial Ads: Best Practices for Successful Campaigns

Interstitial Ads: Best Practices for Successful Campaigns

Interstitial Ads: Best Practices for Successful Campaigns Interstitial ads are full-screen advertisements that appear to grasp the attention of on-site prospects, creating opportunities for brands seeking effective ways to communicate their proposition of value. With such an attention-grabbing format and high-impact visuals, it’s no wonder why interstitial advertising is proving

positive contribution tech

Technology’s Positive Contributions to Society

Technology has and continues to improve our lives. From the business world to the world of medicine, and our day-to-day lives, you can’t go a day without interacting with at least one form of technology. While some fear technology may be going too far, there are many ways in which

How to Choose From The Best Big Data Platforms in 2023

How to Choose From The Best Big Data Platforms in 2023

As big data continues to become increasingly popular in the business world, companies are always looking for better ways to process and analyze complex data. The process critically depends on the platform that manages and analyzes the data. In this article, we will provide a guide to help you choose

Why transparent code is a good idea

Why Transparent Code is a Good Idea

Code is used to make up the apps and software we use every day. From our favorite social media platforms to our online banking services, code is the framework used to build these tools that help make our lives easier. Code is complex. Software today requires large teams of programmers