java.lang.Object
com.aoapps.security.Password
com.aoapps.security.UnprotectedPassword
- All Implemented Interfaces:
AutoCloseable
,Cloneable
,Destroyable
Unlike
Password
, which goes out of its way to protect the password, an unprotected password provides access
to the password value. This is intended for when the password needs to be accessible to the application, such as
providing a generated password to the user.- Author:
- AO Industries, Inc.
-
Field Summary
Fields inherited from class com.aoapps.security.Password
MASKED_PASSWORD
-
Constructor Summary
ConstructorDescriptionGenerates a new password using the default password generator and a defaultSecureRandom
instance, which is not a strong instance to avoid blocking.UnprotectedPassword
(char[] password) UnprotectedPassword
(SupplierE<? extends char[], Ex> generator) Generates a new password using the provided password generator.UnprotectedPassword
(SecureRandom secureRandom) Generates a new password using the default password generator and the providedSecureRandom
source.UnprotectedPassword
(Random random) Deprecated. -
Method Summary
Modifier and TypeMethodDescription<Ex extends Throwable>
voidCalls a consumer, providing a copy of the password.clone()
int
hashCode()
Implements hash code viaArrays.hashCode(char[])
on the password.<R,
Ex extends Throwable>
RCalls a function, providing a copy of the password.<Ex extends Throwable>
booleantest
(PredicateE<? super char[], Ex> predicate) Calls a predicate, providing a copy of the password.
-
Constructor Details
-
UnprotectedPassword
- 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).
-
UnprotectedPassword
Generates a new password using the provided password generator.The password will never be all-zeroes, since this would conflict with the representation of already destroyed. In the unlikely event the generator creates an all-zero password, the password will be discarded and another will be generated. We do recognize that disallowing certain values from the password space may provide an advantage to attackers (i.e. Enigma), losing the all-zero password is probably a good choice anyway.
- Type Parameters:
Ex
- An arbitrary exception type that may be thrown- Throws:
Ex
-
UnprotectedPassword
Deprecated.Please useSecureRandom
. This method will stay, but will remain deprecated since it should only be used after careful consideration.Generates a new password using the default password generator and the providedRandom
source. -
UnprotectedPassword
Generates a new password using the default password generator and the providedSecureRandom
source. -
UnprotectedPassword
public UnprotectedPassword()Generates a new password using the default password generator and a defaultSecureRandom
instance, which is not a strong instance to avoid blocking.
-
-
Method Details
-
hashCode
public int hashCode()Implements hash code viaArrays.hashCode(char[])
on the password. Please note that the hash code may change when destroyed. -
clone
-
invoke
public <R,Ex extends Throwable> R invoke(FunctionE<? super char[], R, throws IllegalStateException, ExEx> function) Calls a function, providing a copy of the password. The copy of the password is zeroed once the function returns.- Type Parameters:
Ex
- An arbitrary exception type that may be thrown- Throws:
IllegalStateException
- whenPassword.isDestroyed()
Ex
-
accept
public <Ex extends Throwable> void accept(ConsumerE<? super char[], Ex> consumer) throws IllegalStateException, ExCalls a consumer, providing a copy of the password. The copy of the password is zeroed once the consumer returns.- Type Parameters:
Ex
- An arbitrary exception type that may be thrown- Throws:
IllegalStateException
- whenPassword.isDestroyed()
Ex
-
test
public <Ex extends Throwable> boolean test(PredicateE<? super char[], Ex> predicate) throws IllegalStateException, ExCalls a predicate, providing a copy of the password. The copy of the password is zeroed once the predicate returns.- Type Parameters:
Ex
- An arbitrary exception type that may be thrown- Throws:
IllegalStateException
- whenPassword.isDestroyed()
Ex
-
SecureRandom
.