java.net.PasswordAuthentication
The class PasswordAuthentication is a data holder that is used by
Authenticator. It is simply a repository for a username and a password.
Methods
1. PasswordAuthentication(String userName, char[] password)
java.net.PasswordAuthentication.PasswordAuthentication(String userName, char[] password)
This method takes two arguments. This method creates a new PasswordAuthentication object from the given username and password.
Note that the given user password is cloned before it is stored in the new PasswordAuthentication object.
Parameters: Two parameters are required for this method.
Username: the user name.
password: the user's password
Java
package com.PasswordAuthentication;import java.net.PasswordAuthentication;public class PasswordAuthentication1 {public static void main(String[] args) {String userName = "admin";char password[] = { 'h', 'e', 'l', 'l', 'o' };PasswordAuthentication passwordAuthentication =new PasswordAuthentication(userName, password);System.out.println(passwordAuthentication);}}
Output:
java.net.PasswordAuthentication@26f0a63f
2. getPassword()
char[] java.net.PasswordAuthentication.getPassword()
This method returns the user password.
Note that this method returns a reference to the password. It is the caller's responsibility to zero out the password information after it is no longer needed.
Parameters: NA
Returns: the password
Exceptions: NA
Java
package com.PasswordAuthentication;import java.net.PasswordAuthentication;public class PasswordAuthenticationgetPassword {public static void main(String[] args) {String userName = "admin";char password[] = { 'h', 'e', 'l', 'l', 'o' };PasswordAuthentication passwordAuthentication =new PasswordAuthentication(userName, password);System.out.println(passwordAuthentication.getPassword());}}
Output:
hello
3. getUserName()
String java.net.PasswordAuthentication.getUserName()
Returns the user name.
Parameters: NA
Returns: the user name.
Exceptions: NA
Java
package com.PasswordAuthentication;import java.net.PasswordAuthentication;public class PasswordAuthenticationgetUserName {public static void main(String[] args) {String userName = "admin";char password[] = { 'h', 'e', 'l', 'l', 'o' };PasswordAuthentication passwordAuthentication =new PasswordAuthentication(userName, password);System.out.println(passwordAuthentication.getUserName());}}
Output:
admin
No comments:
Post a Comment