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