- All Implemented Interfaces:
AutoCloseable
,Cloneable
,Destroyable
- Direct Known Subclasses:
UnprotectedPassword
char[]
as a matter of both convenience and protection.
This does not provide any access to the given password. It is a password black hole: gone forever from outside observers.
Instances of this class are thread-safe.
This class intentionally does not implement equals(java.lang.Object)
and hashCode()
, as it is not
intended to be used in data structures or any complex manipulation. It is solely meant to safely carry a
password.
This class also does not implement Serializable
or Externalizable
. Applications that need to send
passwords across the wire must use another mechanism. Applications that need to store passwords should be using
HashedPassword
.
- Author:
- AO Industries, Inc.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
void
close()
Destroys the password on auto-close.void
destroy()
boolean
int
hashCode()
Uses default implementation fromObject.hashCode()
.boolean
toString()
valueOf
(char[] password) Gets a new password orOptional.empty()
whenpassword == null || password.length == 0
.
-
Field Details
-
MASKED_PASSWORD
A constant used to mask passwords. This is always returned bytoString()
.- See Also:
-
-
Constructor Details
-
Password
- Parameters:
password
- Is zeroed before this method returns. If the original password is needed, pass a copy to this method.- Throws:
IllegalArgumentException
- whenpassword == null || password.length == 0
or whenpassword
is already destroyed (contains all zeroes).- See Also:
-
-
Method Details
-
valueOf
Gets a new password orOptional.empty()
whenpassword == null || password.length == 0
.- Parameters:
password
- Is zeroed before this method returns. If the original password is needed, pass a copy to this method.- Throws:
IllegalArgumentException
- whenpassword
is already destroyed (contains all zeroes).- See Also:
-
toString
- Overrides:
toString
in classObject
- Returns:
- Returns
MASKED_PASSWORD
always.
-
equals
-
hashCode
public int hashCode()Uses default implementation fromObject.hashCode()
. Any meaningful implementation could leak private password information. UseUnprotectedPassword
instead when needing to use in hash-based data structures. -
clone
-
destroy
public void destroy()- Specified by:
destroy
in interfaceDestroyable
-
isDestroyed
public boolean isDestroyed()- Specified by:
isDestroyed
in interfaceDestroyable
-
close
public void close()Destroys the password on auto-close. This use for support of try-with-resources.- Specified by:
close
in interfaceAutoCloseable
-