php - 密码匹配问题
问题描述
以下是我的php代码。我正在尝试对注册进行表单验证,当我提交表单而不填写所有字段时,一切似乎都很好。当我尝试填写所有内容但故意不匹配密码时,它仍然允许我成功注册。
if (isset($_POST['submitted']))
{
if (empty($_POST['useremail']))
$newemailerr = "Email is required!";
else
$newemail = ($_POST['useremail']);
if (empty($_POST['userid']))
$newiderr = "Username is required!";
else
$newid = ($_POST['userid']);
if (empty($_POST['userpass']))
$newpasserr = "Password is required!";
else
$newpass = ($_POST['userpass']);
if (empty($_POST['confirmpass'] && $_POST['confirmpass'] != $_POST['userpass']))
$newconfirmpasserr = "Both passwords do not match!";
else
$newconfirmpass = ($_POST['confirmpass']);
}
解决方案
if (isset($_POST['submitted']))
{
if (empty($_POST['useremail']))
$newemailerr = "Email is required!";
else
$newemail = ($_POST['useremail']);
if (empty($_POST['userid']))
$newiderr = "Username is required!";
else
$newid = ($_POST['userid']);
if (empty($_POST['userpass']))
$newpasserr = "Password is required!";
else
$newpass = ($_POST['userpass']);
if (empty($_POST['confirmpass']) || $_POST['confirmpass'] != $_POST['userpass']) $newconfirmpasserr = "Both passwords do not match!";
else
$newconfirmpass = ($_POST['confirmpass']);
}
你应该在这里使用 OR
if (empty($_POST['confirmpass']) || $_POST['confirmpass'] != $_POST['userpass'])
推荐阅读
- java - 对 BufferedImage 应用抗锯齿
- bash - 如何使用 grep 和 sed 从仅包含国家/地区的 html 文件中获取列表?
- dns - DNS Records and Nameservers
- php - 试图在 symfony 中获取非对象的属性
- vba - Is there a method to use VBA to insert multiple images and insert them in order of selection through the dialog box?
- javascript - Pseudo element :after not displaying
- python - 从循环中返回所有数据
- docker - Docker compose:Traefik 和 Docker 注册表
- javascript - 使用环境变量在“angular.json”中构建期间动态替换文件
- c# - 检测循环 Unity3D 中最后一个对象的位置