html部分
<div aria-hidden="true" role="dialog" tabindex="-1"
id="modal_passwd" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
<h4 class="modal-title">修改密码</h4>
</div>
<section class="panel">
<div class="form-group col-md-12" >
<label class="control-label" for="pop_position">原密码</label>
<input type="password" class="form-control" id="op"
data-placement="bottom" data-content="输入有误" data-trigger="manual">
</div>
<div class="form-group col-md-12" >
<label class="control-label" for="pop_position">新密码</label>
<input type="password" class="form-control" id="np" placeholder="可以是6-22位长度的数字英文特殊字符"
data-placement="bottom" data-content="输入有误" data-trigger="manual">
</div>
<div class="form-group col-md-12" >
<label class="control-label" for="pop_position">重复新密码</label>
<input type="password" class="form-control" id="npag" placeholder="再输入一遍新密码"
data-placement="bottom" data-content="输入有误" data-trigger="manual">
</div>
<div class="text-right modal-footer" style="border-style: none;">
<a href="#" class="btn btn-primary" id="modify_yes">确定</a>
<a href="#" class="btn btn-default" data-dismiss="modal">返回</a>
</div>
</section>
</div>
</div>
</div>
JS部分
$(document).on('click', '#passwd', function (e) {
$("#modal_passwd").modal();
});
//加密
function encrypt_passwd(passwd) {
var code = ['i', 'l', 'f', 'z', 's', 'c'];
var password = $.base64.encode(passwd);
var passwd_head = password.substr(0, 2);
var passwd_foot = password.substr(-2, 2);
var passwd_content_old = password.substr(2, password.length - 4);
var passwd_content_new = passwd_content_old.split("").reverse().join("");
var salt = code[password.length % code.length];
var new_password = salt + passwd_head + passwd_content_new + passwd_foot;
return new_password;
}
$(document).on('click', '#modify_yes', function (e) {
e.preventDefault();
var url = "/index.php?s=/manager/Bettercare/modifyPasswd";
var op = $('#op').val();
var np = $('#np').val();
var npag = $('#npag').val();
var data_post = {};
if (np.length < 6 || np.length > 22) {
toastr.error('密码长度不正确');
return 0;
}
if (np !== npag) {
toastr.error('两次输入的新密码不一致, 请修改');
return 0;
}
data_post = {
"op": encrypt_passwd(op),
"np": encrypt_passwd(np)
};
// return;
$.post(url, data_post, function (data) {
console.log(data);
switch (parseInt(data.status)) {
case 0:
toastr.success('修改成功, 请重新登录');
setTimeout(function () {
window.location = "/index.php?s=/manager/Login/logout";
}, 3000);
$("#modal_passwd").modal('hide');
break;
case 203:
toastr.error('输入的密码不正确, 请重新输入');
break;
case 201:
toastr.error('修改失败, 发生内部错误');
break;
}
}, 'json');
});