// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/codec/MD5Util.java
// public class MD5Util {
// 
//   public static final String DEFAULT_SALT = "minipa_chengjs";
// 
//   /**
//    * 指定加密盐
//    * @param str
//    * @param salt
//    * @return
//    */
//   public static String md5(String str, String salt){
//     if (StringUtil.isNullOrEmpty(salt)) {
//       salt = DEFAULT_SALT;
//     }
//     return new Md5Hash(str,salt).toString() ;
//   }
// 
//   /**
//    * 采用默认加密盐
//    * @param str
//    * @return
//    */
//   public static String md5(String str){
//     return new Md5Hash(str,DEFAULT_SALT).toString() ;
//   }
// 
//   public static void main(String[] args) {
//     String md5 = md5("123456", DEFAULT_SALT) ;
//     System.out.println(md5); // 119d3a4d2dfbca3d23bd1c52a1d6a6e6
//   }
// 
// }


import com.chengjs.cjsssmsweb.common.util.codec.MD5Util;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package com.chengjs.cjsssmsweb.components.shiro;


/**
 * CustomCredentialsMatcher:
 * 密码校验方法继承 SimpleCredentialsMatcher或HashedCredentialsMatcher 实现doCredentialsMatch()
 *
 * author: <a href="mailto:chengjs_minipa@outlook.com">chengjs_minipa</a>, version:1.0.0, 2017/8/28
 */
public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {
  private static final Logger log = LoggerFactory.getLogger(CustomCredentialsMatcher.class);

  @Override
  public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) {
    UsernamePasswordToken token = (UsernamePasswordToken) authcToken;

    Object tokenCredentials = encrypt(String.valueOf(token.getPassword()));
    Object accountCredentials = getCredentials(info);
    //将密码加密与系统加密后的密码校验，内容一致就返回true,不一致就返回false
    return equals(tokenCredentials, accountCredentials);
  }

  /**
   * 将传进来密码加密方法
   * @param data
   * @return
   */
  private String encrypt(String data) {
// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/common/util/codec/MD5Util.java
// public class MD5Util {
// 
//   public static final String DEFAULT_SALT = "minipa_chengjs";
// 
//   /**
//    * 指定加密盐
//    * @param str
//    * @param salt
//    * @return
//    */
//   public static String md5(String str, String salt){
//     if (StringUtil.isNullOrEmpty(salt)) {
//       salt = DEFAULT_SALT;
//     }
//     return new Md5Hash(str,salt).toString() ;
//   }
// 
//   /**
//    * 采用默认加密盐
//    * @param str
//    * @return
//    */
//   public static String md5(String str){
//     return new Md5Hash(str,DEFAULT_SALT).toString() ;
//   }
// 
//   public static void main(String[] args) {
//     String md5 = md5("123456", DEFAULT_SALT) ;
//     System.out.println(md5); // 119d3a4d2dfbca3d23bd1c52a1d6a6e6
//   }
// 
// }


// Path: cjs_ssms_web/src/main/java/com/chengjs/cjsssmsweb/components/shiro/CustomCredentialsMatcher.java
import com.chengjs.cjsssmsweb.common.util.codec.MD5Util;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

package com.chengjs.cjsssmsweb.components.shiro;


/**
 * CustomCredentialsMatcher:
 * 密码校验方法继承 SimpleCredentialsMatcher或HashedCredentialsMatcher 实现doCredentialsMatch()
 *
 * author: <a href="mailto:chengjs_minipa@outlook.com">chengjs_minipa</a>, version:1.0.0, 2017/8/28
 */
public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {
  private static final Logger log = LoggerFactory.getLogger(CustomCredentialsMatcher.class);

  @Override
  public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) {
    UsernamePasswordToken token = (UsernamePasswordToken) authcToken;

    Object tokenCredentials = encrypt(String.valueOf(token.getPassword()));
    Object accountCredentials = getCredentials(info);
    //将密码加密与系统加密后的密码校验，内容一致就返回true,不一致就返回false
    return equals(tokenCredentials, accountCredentials);
  }

  /**
   * 将传进来密码加密方法
   * @param data
   * @return
   */
  private String encrypt(String data) {
    String encrypt = MD5Util.md5(data, "");