use of org.eclipse.hono.auth.EncodedPassword in project hono by eclipse.
the class Credentials method createPasswordSecret.
/**
* Create a new password secret.
*
* @param password The password to use.
* @param bcryptCostFactor The cost factor to use for creating a bcrypt password hash.
* @return The password secret instance.
*/
public static PasswordSecret createPasswordSecret(final String password, final OptionalInt bcryptCostFactor) {
final SpringBasedHonoPasswordEncoder encoder = new SpringBasedHonoPasswordEncoder(bcryptCostFactor.orElse(SpringBasedHonoPasswordEncoder.DEFAULT_BCRYPT_STRENGTH));
final EncodedPassword encodedPwd = EncodedPassword.fromHonoSecret(encoder.encode(password));
final PasswordSecret s = new PasswordSecret();
s.setHashFunction(encodedPwd.hashFunction);
if (encodedPwd.salt != null) {
s.setSalt(Base64.getEncoder().encodeToString(encodedPwd.salt));
}
s.setPasswordHash(encodedPwd.password);
return s;
}
Aggregations