以此为例,加密商家的密码
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String password = passwordEncoder.encode(seller.getPassword());
seller.setPassword(password);
加密之后数据库里存储的就是一段密文
需要在spring security框架配置一下
<authentication-manager>
<!--引入自定义认证-->
<authentication-provider user-service-ref="userDetailsService">
<password-encoder ref="bCryptPasswordEncoder"/>
</authentication-provider>
</authentication-manager>
<!--加密-->
<beans:bean class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" id="bCryptPasswordEncoder"/>
在用户注册时候应该利用加密算法加密用户密码,框架配置之后在登陆的时候框架会自动将用户密码与数据库的密文对比.