Web 正确的javascript预检查方法;更改密码";对话
这个问题不是关于安全或“如何正确实现”相关问题,而是关于预先检查输入值的概念 作为第一种方法,我尝试实现以下过程(请注意,在每个Web 正确的javascript预检查方法;更改密码";对话,web,dialog,verification,Web,Dialog,Verification,这个问题不是关于安全或“如何正确实现”相关问题,而是关于预先检查输入值的概念 作为第一种方法,我尝试实现以下过程(请注意,在每个check if语句中,如果为false,该方法将返回一个标识符值,否则算法将继续) 这种方法引起了一些问题,我认为它与异步ajax请求有关。我返回一个特定的标识符整数,并调用如下方法 switch(checkPasswords(oldPW, newPW1, newPW2){ case 0: // alert something suitable
check if
语句中,如果为false,该方法将返回一个标识符值,否则算法将继续)
这种方法引起了一些问题,我认为它与异步ajax请求有关。我返回一个特定的标识符整数,并调用如下方法
switch(checkPasswords(oldPW, newPW1, newPW2){
case 0:
// alert something suitable
break;
case 1:
// alert something suitable
break;
//(...)
case n-1:
// alert something suitable
break;
case n:
// everything is ok, change password
break;
}
最后检查旧密码是否更干净?或者甚至在尝试更改密码时直接更改密码(假设新的所需密码满足要求),结果是只有一个ajax请求?常见的概念是什么?我个人建议在用户离开旧密码输入(onblur)时,通过检查旧密码来分离Ajax请求,并拥有自己的处理程序/成功函数和第二个处理密码实际更改的函数 鉴于此标记:
<input type="text" id="oldPassword" value="" />
<input type="text" id="newPassword" name="newPassword" value="" />
<input type="text" id="confirmNewPassword" name="confirmNewPassword" value="" />
<input type="button" id="submitButton" value="Reset Password" />
这个(伪代码)JS:
//一些doc-ready-ish函数
$('#oldPassword').blur(函数(){
//验证pw的ajax请求
//触发一些成功/失败消息
//如果失败,请通过取消绑定click事件或类似操作来禁用“提交”按钮
//如果成功,请确保再次绑定提交按钮事件
});
$(“#提交按钮”)。单击(函数(){
//执行新的pw验证
//提交重置密码请求
});
<input type="text" id="oldPassword" value="" />
<input type="text" id="newPassword" name="newPassword" value="" />
<input type="text" id="confirmNewPassword" name="confirmNewPassword" value="" />
<input type="button" id="submitButton" value="Reset Password" />
<script type="text/javascript">
//some doc ready-ish function
$('#oldPassword').blur(function(){
//ajax request to validate the pw
//trigger some success / failure message
//if failure, disable your #submitButton by unbinding the click event or something to that effect
//if its successful, make sure you're submit button event is bound again
});
$('#submitButton').click(function(){
//perform new pw validation
//submit your reset password request
});
</script>