-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw exception before hashing when password is null
- Loading branch information
1 parent
6ddbf76
commit f978f9d
Showing
1 changed file
with
26 additions
and
22 deletions.
There are no files selected for viewing
48 changes: 26 additions & 22 deletions
48
plume-admin-ws/src/main/java/com/coreoz/plume/admin/services/hash/BCryptHashService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |