Search in sources :

Example 1 with EncodedPassword

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;
}
Also used : SpringBasedHonoPasswordEncoder(org.eclipse.hono.auth.SpringBasedHonoPasswordEncoder) EncodedPassword(org.eclipse.hono.auth.EncodedPassword)

Aggregations

EncodedPassword (org.eclipse.hono.auth.EncodedPassword)1 SpringBasedHonoPasswordEncoder (org.eclipse.hono.auth.SpringBasedHonoPasswordEncoder)1