java.net.PasswordAuthentication Class in Java
Last Updated :
28 Mar, 2021
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 Type |
getUserName() |
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
import java.io.*;
import java.net.PasswordAuthentication;
class GFG {
public static void main(String args[])
{
GFG acc = new GFG();
acc.proceed();
}
private void proceed()
{
String userName = "Geek" ;
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());
System.out.println(
"Password: "
+ passwordAuthentication.getPassword());
System.out.println(
"Password: "
+ String.copyValueOf(
passwordAuthentication.getPassword()));
}
}
|
Output
UserName: Geek
Password: [C@4e50df2e
Password: geekgorgeeks
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...