我发现了一些类似的问题。但是我仍然无法解决这个问题。我在确认密码验证时遇到问题。如果我在密码输入中写了一些东西,然后在我的 cpassword 输入中写了相同的密码,它会验证 cpassword。但是,如果我从密码中删除一个字母,cpassword 仍然认为它是正确的。
这是我的 cpassword-check.js
// Validate confirm password while typing
$(document).ready(function() {
$('#cpassword').click(function(){
var cpassword = $('#cpassword').val();
if (cpassword.length > 0) {
$("#resultcpass").html('<i class="fa fa-circle-o-notch fa-spin loading-icon"></i>');
$.ajax({
type : 'POST',
url : 'cpassword-check.php',
data : {
cpassword: $('#cpassword').val(),
password: $('#password').val()
},
success : function(data) {
$("#resultcpass").html(data);
}
});
return false;
} else {
$("#resultcpass").html('');
}
});
});
这就是它验证它的地方(cpassword-check.php):
/*$host="localhost";
$user="root";
$pass="";
$dbname="lr";
$dbcon = new PDO("mysql:host={$host};dbname={$dbname}",$user,$pass);*/
if($_POST['cpassword']) {
$cpassword = strip_tags($_POST['cpassword']);
$password = strip_tags($_POST['password']);
if ( $cpassword != $password) {
echo "<i class='fa fa-circle user-validation-w pull-right' aria-hidden='true'></i><span class='availability pull-right'> Deben coincidir</span>";
} else {
echo "<i class='fa fa-check user-validation-ok pull-right' aria-hidden='true'></i><span class='availability pull-right'></span>";
}
}
请您帮助我每秒执行一次该功能,或者即使密码更改,也可以做其他事情来验证 cpassword?
谢谢!