Skip to content

Commit

Permalink
Throw exception before hashing when password is null
Browse files Browse the repository at this point in the history
  • Loading branch information
jfardilha2 committed Aug 24, 2023
1 parent 6ddbf76 commit f978f9d
Showing 1 changed file with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package com.coreoz.plume.admin.services.hash;

import javax.inject.Singleton;

import org.mindrot.jbcrypt.BCrypt;

@Singleton
public class BCryptHashService implements HashService {

private static final int BCRYPT_SALT_ROUND = 11;

@Override
public String hashPassword(String password) {
return BCrypt.hashpw(password, BCrypt.gensalt(BCRYPT_SALT_ROUND));
}

@Override
public boolean checkPassword(String candidate, String hashed) {
return BCrypt.checkpw(candidate, hashed);
}

}
package com.coreoz.plume.admin.services.hash;

import javax.inject.Singleton;

import com.google.common.base.Strings;
import org.mindrot.jbcrypt.BCrypt;

@Singleton
public class BCryptHashService implements HashService {

private static final int BCRYPT_SALT_ROUND = 11;

@Override
public String hashPassword(String password) {
if (password == null) {
throw new IllegalArgumentException("Password must not be null or empty");
}
return BCrypt.hashpw(password, BCrypt.gensalt(BCRYPT_SALT_ROUND));
}

@Override
public boolean checkPassword(String candidate, String hashed) {
return BCrypt.checkpw(candidate, hashed);
}

}

0 comments on commit f978f9d

Please sign in to comment.