I would like to know if my current BCrypt implementation is correct, I know that I am not using BCrypt.checkpw() , which can lead to a problem, so this is the main reason I check it here.
Hasher.java container class:
abstract public class Hasher { public static String hash(final char[] input) { String output = Hasher.hash(new String(input)); for (int i = 0; i < input.length; i++) { input[i] = 0; } return output; } public static String hash(final String input) { return BCrypt.hashpw(input, BCrypt.gensalt()); } }
Here's one problem: JPasswordField gives me char[] for security reasons, however BCrypt.hashpw() only accepts strings. How can I avoid String floating in my memory?
Client implementation of login:
String hashedPassword = Hasher.hash(password); Network.getInstance().send("login " + username + " " + hashedPassword);
So, the hash is sent over the network, currently the network is not encrypted, but I plan to add this.
Server implementation when creating an account:
public static Account createAccount(final String username, final String password) { String hashedPassword = Hasher.hash(password.toCharArray()); return new Account(username, hashedPassword); }
Password Verification Server Implementation:
public boolean checkPassword(final String hashedPassword) { return this.hashedPassword.equals(hashedPassword); }
With this.hashedPassword a hash that resides in the serverβs memory (which comes from the database at boot time).
Properties of my installation:
- Logging into the system takes a considerable amount of time from the client, since the password is hashed there.
- Creating an account / Changing the password takes a considerable time of the server, since then the password is hashed on the server.
- When checking login attempts, the server practically does not require time, since hashing is not required.
- If someone grabs a database containing hashes, then it will take some time to crack the password for each account.
- I still need to find out a good performance factor for
BCrypt.gensalt() .
Please check my assumptions.
Sincerely.