document-management-system icon indicating copy to clipboard operation
document-management-system copied to clipboard

Can I change password's hash algorithm?

Open Regentag opened this issue 4 years ago • 5 comments

I want to change the hash algorithm of user account password from MD5 to SHA256 or bcrypt. I tried changing the Hash algorithm in the OpenKM.xml file, but it didn't work well. If the user changes the password, it is saved as MD5 in the DB and cannot log in again.

<security:password-encoder hash="md5"/>

Can I modify the settings to use SHA256 or bcrypt? OpenKM version is 6.3.9(CE).

Regentag avatar Dec 14 '20 14:12 Regentag

Take a look here https://github.com/openkm/document-management-system/blob/5c63b47d4661af625eea370b1d536a7a30211d89/src/main/java/com/openkm/dao/AuthDAO.java#L48

Because this is a radical change in the repository will be better to set a configuration parameter to switch between md5 and the new password crypt. Take a look at this class about how to create a new configuration parameter https://github.com/openkm/document-management-system/blob/master/src/main/java/com/openkm/core/Config.java ( use it to switch between md5 -> default and bcrypt )

I suggest something like

import import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

BCryptPasswordEncoder bcrypt = new BCryptPasswordEncoder();
			user.setPassword(bcrypt.encode(user.getPassword()));

darkman97i avatar Dec 16 '20 16:12 darkman97i

@darkman97i Thank you for answer. If so, there is no way to apply it without modifying the source code.

Regentag avatar Jan 18 '21 10:01 Regentag

No, in the code when you create a new user and set the password must use the right crypt type to store in the database. That happens with all the applications adding or changing password algorithm it means changes in the code ( in this case minimal changes )

darkman97i avatar Jan 19 '21 07:01 darkman97i

For personal use, I made a SHA-256 patch for version 6.3.9. https://github.com/Regentag/openkm_6.3.9ce_sha256

Regentag avatar Jan 19 '21 12:01 Regentag

We will try to add in the next release ... in future better fork the project and then ask for a pull request from your branch to ours.

@gnujavasergio ask me before working on it

darkman97i avatar Jan 19 '21 18:01 darkman97i