package com.njcn.shiro.PasswordMatcher;


import com.njcn.sso.pojo.user.User;
import com.njcn.shiro.token.ShiroToken;
import com.njcn.utils.MD5;
import com.njcn.utils.ThreeDes;
import org.apache.shiro.authc.AccountException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;


/**
 * @author hongawen
 * @date 2018/3/26 11:25
 */
public class PasswordMatcher  extends SimpleCredentialsMatcher {


    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        //前台页面用户输入的用户名、密码
//        ShiroToken shiroToken= (ShiroToken) token;
//        //根据用户名查询出来的密码
//        String dbPassword=info.getCredentials().toString();
//        User user= (User) info.getPrincipals().getPrimaryPrincipal();
//        String secretKey = user.getSecretKey();
//        String standBy = user.getStandBy();
//        // 开始校验用户的密码是否正确
//        String pwd = shiroToken.getPswd();
//        String mPwd= MD5.twiceMD5(pwd);
//        // 两次MD加密是否一致，一致后继续验证
//        if (standBy.equalsIgnoreCase(mPwd)) {
//            // 验证3des加密后是否一致
//            Boolean flag = ThreeDes.hex(dbPassword, standBy + secretKey);
//            if (!flag) {
//                throw new AccountException("请输入正确的密码");
//            }else{
//                return  Boolean.TRUE;
//            }
//        } else {
//            throw new AccountException("请输入正确的密码");
//        }
        return true;
    }


}
