var  remindLayer ;
    function confirmIndentity(username,fn) {
    username = encrypt(username);
    remindLayer = layer.open({
        type: '1',
        title: "密码确认",
        resize: false,
        shadeClose: true,
        scrollbar: false,
        area: "350px",
        closeBtn: 0,
        content: "<form class='form-horizontal pdr15 pdt15 pdl15'><div class='form-group'><label for='newPwd' class='col-sm-3 control-label'>密码</label><div class='col-sm-9'><input type='password' class='form-control' id='confirmPwd' autocomplete='new-password'></div></div></form>",
        btn: ['确定', '取消'],
        yes: function (index, layero) {
            var confirmPwd = $("#confirmPwd").val();
            confirmPwd = confirmPwd.replace(/(^\s*)|(\s*$)/g, '');
            if (validPassword(confirmPwd)) {
                //执行更新用户密码的操作
                $.ajax({
                    type: "POST",
                    url: "/sso/user/generateSM2Key",
                    dataType: "text",
                    async:false,
                    data: {
                        username: username
                    },
                    success: function (data) {
                        var info = $.parseJSON(data);
                        if (info.code === 200) {
                            var pubkeyHex = info.body;//获取SM2加密公钥
                            var sm3Pwd = sm3Digest(confirmPwd);//SM3加密
                            var sm2Pwd =sm2Encrypt(sm3Pwd + "|" + confirmPwd, pubkeyHex, 0);//SM2公钥加密
                            confirmUserPwd(sm2Pwd,fn);
                        }else {
                            layer.msg(info.message, {icon: 2, time: 2000});
                        }
                    }
                });
            } else {
                layer.msg('密码不正确', {icon: 2, time: 2000});
            }
        }, btn2: function (index, layero) {
            layer.close(index);
        },
        end: function (index) {
            layer.close(index);
        }
    })
}

/**
 * 加密（需要先加载lib/aes/aes.min.js文件）
 * @param word
 * @returns {*}
 */
function encrypt(word) {
    var key = CryptoJS.enc.Utf8.parse("njcnpqsqpncjnggg");
    var srcs = CryptoJS.enc.Utf8.parse(word);
    var encrypted = CryptoJS.AES.encrypt(srcs, key, {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7});
    return encrypted.toString();
}



//验证用户密码
function validPassword(password) {
    password = password.replace(/(^\s*)|(\s*$)/g, '');
    var pwdRepx = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[@#_!$%^&*()?<>/|~,\\\-+\.]).{8,16}$/;
    if (!pwdRepx.test(password)) {
        return false;
    }
    return true;
}

//判断用户名密码是否匹配
function confirmUserPwd(pwd,fn) {
    $.ajax({
        type: "POST",
        url: "/pqs9000/user/confirmPwd",
        dataType: "json",
        async:false,
        data: {
            password: pwd
        },
        statusCode: {
            203: function () {
                layer.msg("密码正确", {icon: 6, time: 2000}, function(){
                    layer.close(remindLayer);
                    //执行传递过来的函数内容
                    fn();
                });
            }
        },
        success: function (data) {
            if (data.code === 500) {
                layer.msg(data.message, {icon:2, time: 2000});
            }
        }
    })
}