Using BCrypt for password encryption


Cuba offers two encryption type out of the box (md5 and sha1). Since they are not very secure I would like to use BCrypt for encrypting my password.

This can be done by implementing my own EncryptionModule ([]). After implementing the different get*Hash()-methods I am now stuck with the checkPassword method:

EncryptionModule.checkPassword(User user, String givenPassword);

I expected that givenPassword would be the plain text password that the user entered. Actually it the givenPassword is already encrypted. My problem is that I need he plain text password and the previously encrypted password to check if they are equal.
(see spring security implementation: [])

How can I implement BCrypt for password encryption in cuba?



AppLoginWindow passes a password hash to middleware which is obtained with EncryptionModule.getPlainHash call.

If you want to implement your BCrypt EncryptionModule you can either implement it as Md5EncryptionModule (where EncryptionModule.checkPassword simply compares plain hash and a user password field) or you can return password from getPlainHash without encryption and implement all the hash checks in checkPassword method. In the second case password will be passed to EncryptionModule.checkPassword without encryption.

In fact Sha1EncryptionModule now performs two hash procedures, first without salt in getPlainHash and second with encrypted password and salt in the checkPassword method.