1. /*
  2. * @(#)PasswordAuthentication.java 1.7 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.net;
  8. /**
  9. * The class PasswordAuthentication is a data holder that is used by
  10. * Authenticator. It is simply a repository for a user name and a password.
  11. *
  12. * @see java.net.Authenticator
  13. * @see java.net.Authenticator#getPasswordAuthentication()
  14. *
  15. * @author Bill Foote
  16. * @version 1.7, 11/29/01
  17. * @since JDK1.2
  18. */
  19. public final class PasswordAuthentication {
  20. private String userName;
  21. private char[] password;
  22. /**
  23. * Creates a new <code>PasswordAuthentication</code> object from the given
  24. * user name and password.
  25. *
  26. * <p> Note that the given user password is cloned before it is stored in
  27. * the new <code>PasswordAuthentication</code> object.
  28. *
  29. * @param userName the user name
  30. * @param password the user's password
  31. */
  32. public PasswordAuthentication(String userName, char[] password) {
  33. this.userName = userName;
  34. this.password = (char[])password.clone();
  35. }
  36. /**
  37. * Returns the user name.
  38. *
  39. * @return the user name
  40. */
  41. public String getUserName() {
  42. return userName;
  43. }
  44. /**
  45. * Returns the user password.
  46. *
  47. * <p> Note that this method returns a reference to the password. It is
  48. * the caller's responsibility to zero out the password information after
  49. * it is no longer needed.
  50. *
  51. * @return the password
  52. */
  53. public char[] getPassword() {
  54. return password;
  55. }
  56. }