Interface HashingPasswordService
-
- All Superinterfaces:
PasswordService
- All Known Implementing Classes:
DefaultPasswordService
public interface HashingPasswordService extends PasswordService
AHashingPasswordService
is aPasswordService
that performs password encryption and comparisons based on cryptographicHash
es.- Since:
- 1.2
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description org.apache.shiro.crypto.hash.Hash
hashPassword(Object plaintext)
Hashes the specified plaintext password using internal hashing configuration settings pertinent to password hashing.boolean
passwordsMatch(Object plaintext, org.apache.shiro.crypto.hash.Hash savedPasswordHash)
Returnstrue
if thesubmittedPlaintext
password matches the existingsavedPasswordHash
,false
otherwise.-
Methods inherited from interface org.apache.shiro.authc.credential.PasswordService
encryptPassword, passwordsMatch
-
-
-
-
Method Detail
-
hashPassword
org.apache.shiro.crypto.hash.Hash hashPassword(Object plaintext) throws IllegalArgumentException
Hashes the specified plaintext password using internal hashing configuration settings pertinent to password hashing. Note that this method is only likely to be used in more complex environments that wish to format and/or save the returnedHash
object in a custom manner. Most applications will find theencryptPassword
method suitable enough for safety and ease-of-use.Usage
The input argument type can be any 'byte backed'Object
- almost always either a String or character array representing passwords (character arrays are often a safer way to represent passwords as they can be cleared/nulled-out after use. Any argument type supported byByteSource.Util.isCompatible(Object)
is valid. Regardless of your choice of using Strings or character arrays to represent submitted passwords, you can wrap either as aByteSource
by usingByteSource.Util
, for example, when the passwords are captured as Strings:ByteSource passwordBytes = ByteSource.Util.bytes(submittedPasswordString); Hash hashedPassword = hashingPasswordService.hashPassword(passwordBytes);
or, identically, when captured as a character array:ByteSource passwordBytes = ByteSource.Util.bytes(submittedPasswordCharacterArray); Hash hashedPassword = hashingPasswordService.hashPassword(passwordBytes);
- Parameters:
plaintext
- the raw password as 'byte-backed' object (String, character array,ByteSource
, etc) usually acquired from your application's 'new user' or 'password reset' workflow.- Returns:
- the hashed password.
- Throws:
IllegalArgumentException
- if the argument cannot be easily converted to bytes as defined byByteSource.Util.isCompatible(Object)
.- See Also:
ByteSource.Util.isCompatible(Object)
,PasswordService.encryptPassword(Object)
-
passwordsMatch
boolean passwordsMatch(Object plaintext, org.apache.shiro.crypto.hash.Hash savedPasswordHash)
Returnstrue
if thesubmittedPlaintext
password matches the existingsavedPasswordHash
,false
otherwise. Note that this method is only likely to be used in more complex environments that save hashes in a custom manner. Most applications will find thepasswordsMatch(plaintext,string)
method sufficient ifencrypting passwords as Strings
.Usage
ThesubmittedPlaintext
argument type can be any 'byte backed'Object
- almost always either a String or character array representing passwords (character arrays are often a safer way to represent passwords as they can be cleared/nulled-out after use. Any argument type supported byByteSource.Util.isCompatible(Object)
is valid.- Parameters:
plaintext
- a raw/plaintext password submitted by an end user/Subject.savedPasswordHash
- the previously hashed password known to be associated with an account. This value is expected to have been previously generated from thehashPassword
method (typically when the account is created or the account's password is reset).- Returns:
true
if theplaintext
password matches the existingsavedPasswordHash
,false
otherwise.
-
-