Class PasswordValue

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class PasswordValue
    extends java.lang.Object
    implements java.io.Closeable
    Wrapper for a password, held in a char[] array.

    Closing an instance will clear the characters of the char array.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      PasswordValue clone()  
      void close()
      Clears the password characters by overwriting them with '\0's.
      static PasswordValue copyOf​(char[] password)
      Creates a new PasswordValue using a copy the specified characters.
      boolean equals​(java.lang.Object obj)  
      char[] getPasswordChars()
      Returns a reference to the current password characters.
      int hashCode()  
      static PasswordValue wrap​(char[] password)
      Creates a new PasswordValue by wrapping the specified character array.
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • copyOf

        public static PasswordValue copyOf​(char[] password)
        Creates a new PasswordValue using a copy the specified characters.
        Parameters:
        password - password characters
        Returns:
        new PasswordValue instance
      • wrap

        public static PasswordValue wrap​(char[] password)
        Creates a new PasswordValue by wrapping the specified character array.

        The new instance will take ownership of the char array, and clear it when the instance is closed.

        Parameters:
        password - password characters
        Returns:
        new PasswordValue instance
      • clone

        public PasswordValue clone()
        Overrides:
        clone in class java.lang.Object
      • close

        public void close()
        Clears the password characters by overwriting them with '\0's.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • getPasswordChars

        public char[] getPasswordChars()
        Returns a reference to the current password characters.
        Returns:
        reference to the current password characters
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object