简体   繁体   English

PHP和Javascript密码匹配验证

[英]PHP and Javascript Validation of Password Match

Trying to get page to dynamically show if passwords match (echo 'Match' or 'Do not match'). 尝试获取页面以动态显示密码是否匹配(回显“匹配”或“不匹配”)。 (Similiar to previous question asked here .) (类似于先前在此处提出的问题。)

Looking to check if password1 and password2 are the same as you type in either the 'password' or 'confirm password' input boxes. 想要检查password1和password2是否与您在“密码”或“确认密码”输入框中键入的相同。

EDIT: Seems elseif ($password2 == $password1) isn't checking for the match as I intended. 编辑:似乎elseif($ password2 == $ password1)没有按照我的预期检查匹配项。 Posting of password1 and password2 works (#feedback changes to 'Do not match' as you type in either input box, but 'Match' never shows). 密码1和密码2的发布有效(当您在任一输入框中键入时,#feedback更改为“不匹配”,但“匹配”从不显示)。 Any help on how to fix this code is appreciated. 感谢您提供有关如何修复此代码的任何帮助。

check.php check.php

<?php
include __DIR__ . '/mysqli_connect.php';

$password2 = mysqli_real_escape_string($dbc, $_POST['password2']);
$password1 = mysqli_real_escape_string($dbc, $_POST['password1']);

if ($password2==NULL && $password1==NULL) {
    echo '';
} elseif ($password2 == $password1) {
    echo 'Match';
} else {
    echo 'Do not match';
}

register.php register.php

<script type="text/javascript" src="/jquery-3.2.1.min.js"></script>

<script>
$(document).ready(function() {
    $('#feedback').load('/includes/check.php').show();

    $('#password1').keyup(function() {
        $.post('/includes/check.php', { password1: form.password1.value }, 
        function(result) {
            $('#feedback').html(result).show;
        });
    });
});

$(document).ready(function() {
    $('#feedback').load('/includes/check.php').show();

    $('#password2').keyup(function() {
        $.post('/includes/check.php', { password2: form.password2.value }, 
        function(result) {
            $('#feedback').html(result).show;
        });
    });
});
</script>

<form action="register.php" method="post" name="form">

<input id="password1" class="signup_input_box" type="password" name="password1" maxlength="20" value="<?php if (isset($trimmed['password1'])) echo $trimmed['password1']; ?>">

<input id="password2" class="signup_input_box" type="password" name="password2" maxlength="20" value="<?php if (isset($trimmed['password2'])) echo $trimmed['password2']; ?>">
<div id="feedback"></div>

<p><center><input type="submit" name="submit" value="Register"></center>
</form>

Skipped using MySql posting and used JS only to check the value of the password inputs and show text upon keyup. 使用MySql发布跳过,仅使用JS来检查密码输入的值并在键入键时显示文本。 Reference here. 参考这里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM