Spring Security-用户密码自定义加密

时间:2021-12-15 13:26:39

public class SunPasswordEncoder implements PasswordEncoder{

//@实现加密的方法,既将明文转换为密文的方法
 public String encodePassword(String rawPass, Object salt)
   throws DataAccessException {
  String pass = null;
  try {
   pass = Tools.encryptBasedDes(rawPass);
  } catch (Exception e) {
   e.printStackTrace();
  }
  return pass;
 }

//@验证密码是否有效的方法,返回'true'则登录成功

public boolean isPasswordValid(String encPass, String rawPass, Object salt)
   throws DataAccessException {
  
  String pass1 = "" + encPass;
  String pass2 = encodePassword(rawPass, salt);
  return pass1.equals(pass2);
 }

<bean id="myEncoder" class="com.xxx.common.SunPasswordEncoder" />
  
 <!-- 后台管理权限认证 -->
 <sec:authentication-provider user-service-ref="xxxxxxServiceImpl">
  <!-- sec:password-encoder hash="md5" / -->
  <sec:password-encoder ref="myEncoder" />
 </sec:authentication-provider>

加密方式:http://blog.csdn.net/s445320/article/details/9897189