Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/main/java/org/mindrot/BCrypt.java
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,15 @@ public byte[] crypt_raw(byte password[], byte salt[], int log_rounds,
return ret;
}

/**
* Hash a password using the OpenBSD bcrypt scheme with a random salt
* @param password the password to hash
* @return the hashed password
*/
public static String hashpw(String password) {
return hashpw(password, BCrypt.gensalt());
}

/**
* Hash a password using the OpenBSD bcrypt scheme
* @param password the password to hash
Expand All @@ -662,7 +671,7 @@ public static String hashpw(String password, String salt) {
off = 3;
else {
minor = salt.charAt(2);
if (minor != 'a' || salt.charAt(3) != '$')
if ((minor < 'a' || minor > 'z') || salt.charAt(3) != '$')
throw new IllegalArgumentException ("Invalid salt revision");
off = 4;
}
Expand Down Expand Up @@ -717,7 +726,7 @@ public static String gensalt(int log_rounds, SecureRandom random) {

random.nextBytes(rnd);

rs.append("$2a$");
rs.append("$2y$");
if (log_rounds < 10)
rs.append("0");
if (log_rounds > 30) {
Expand Down