Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Security : Encrypt password

I am using spring 3.2.5. Righ now i am hashing password using

        MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
        messageDigest.update(password.getBytes("UTF-8"));
        byte[] digestBytes = messageDigest.digest();

I want to secure password using methods provided by spring. I searched internet and most of the post are very old. So any example will be fine.

like image 304
Manish Kumar Avatar asked Mar 03 '26 18:03

Manish Kumar


1 Answers

You can use org.springframework.security.crypto.password.StandardPasswordEncoder class. It is a lot less hassle, you don't have to worry about salt and iterations - the details are completely encapsulated within the encoder.

<!-- password encoder -->
<beans:bean id="encoder" class="org.springframework.security.crypto.password.StandardPasswordEncoder" />


<!-- This is the authentication manager -->
<authentication-manager>
   <authentication-provider user-service-ref="authService">
    <password-encoder ref="encoder" />
   </authentication-provider>
</authentication-manager>

Visit this site to know more.

like image 119
Jeevan Patil Avatar answered Mar 05 '26 07:03

Jeevan Patil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!