Class BCryptPasswordEncoder
java.lang.Object
com.codename1.backend.security.crypto.BCryptPasswordEncoder
- All Implemented Interfaces:
PasswordEncoder
bcrypt, as OpenBSD defined it and Spring's BCryptPasswordEncoder writes it:
$2a$, $2b$ or $2y$, a cost, a 16 byte salt and a 23 byte hash.
$2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy
Registered as {bcrypt}, so passwords hashed by a Spring application verify
unchanged. It is written in Java -- this runtime has no native Blowfish -- and
at cost 10 one check is tens of milliseconds of a host thread, which is why
new passwords are encoded with {pbkdf2-sha256} instead. Only the first 72
bytes of a password take part, as in every bcrypt.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe cost Spring uses unless told otherwise. -
Constructor Summary
ConstructorsConstructorDescriptionAn encoder of costDEFAULT_STRENGTHwriting$2a$.BCryptPasswordEncoder(char version, int strength) BCryptPasswordEncoder(int strength) -
Method Summary
Modifier and TypeMethodDescriptionencode(CharSequence rawPassword) The password as it should be stored: salted and hashed, so encoding one password twice gives two different results.booleanmatches(CharSequence rawPassword, String encodedPassword) WhetherrawPasswordis the passwordencodedPasswordwas made from.booleanupgradeEncoding(String encodedPassword) True when the stored password was made with a lower cost than this encoder's.
-
Field Details
-
DEFAULT_STRENGTH
public static final int DEFAULT_STRENGTHThe cost Spring uses unless told otherwise.- See Also:
-
-
Constructor Details
-
BCryptPasswordEncoder
public BCryptPasswordEncoder()An encoder of costDEFAULT_STRENGTHwriting$2a$. -
BCryptPasswordEncoder
public BCryptPasswordEncoder(int strength) - Parameters:
strength- the cost, 4 to 31: the work doubles with every step
-
BCryptPasswordEncoder
public BCryptPasswordEncoder(char version, int strength) - Parameters:
version- the letter after$2: 'a', 'b' or 'y'strength- the cost, 4 to 31
-
-
Method Details
-
encode
Description copied from interface:PasswordEncoderThe password as it should be stored: salted and hashed, so encoding one password twice gives two different results.- Specified by:
encodein interfacePasswordEncoder
-
matches
Description copied from interface:PasswordEncoderWhetherrawPasswordis the passwordencodedPasswordwas made from.- Specified by:
matchesin interfacePasswordEncoder
-
upgradeEncoding
True when the stored password was made with a lower cost than this encoder's.- Specified by:
upgradeEncodingin interfacePasswordEncoder
-