php - MySQL密码检查器

标签 php database string

我的问题:

我有一个密码检查器,可确保密码在插入数据库之前不超过 25 个或 <5 个字符。如果是,它会报错。一切正常,但我似乎无法让它检查密码是否不是 <5 和/或 >25 个字符,然后将其放入数据库。

代码部分:

if (strlen($pswd)>30) {
echo "Your password is too long! Password's should be between 5 and 30 characters long!";
}

if (strlen($pswd)<5) {
echo "Your password is too short! Password's should be between 5 and 30 characters long!";
}

else if (!strlen($pswd)>30||strlen($pswd)<5)
{
$query = mysql_query("INSERT INTO users VALUES ('','$un','$fn','$ln','$em','$pswd','$d','0')");
die("<h2>Welcome to M8Ster</h2>Please login to your account to get started ...");
}

最佳答案

尝试将所有 if 语句组合成一个 if-elseif-else:

if (strlen($pswd)>30) {
    echo "Your password is too long! Password's should be between 5 and 30 characters long!";
} else if (strlen($pswd)<5) {
    echo "Your password is too short! Password's should be between 5 and 30 characters long!";
} else {
    $query = mysql_query("INSERT INTO users VALUES ('','$un','$fn','$ln','$em','$pswd','$d','0')");
    die("<h2>Welcome to M8Ster</h2>Please login to your account to get started ...");
}

关于php - MySQL密码检查器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13783026/

相关文章:

java - 正则表达式从 JSON 字符串中提取对象

C++、COM 和传递字符串

php - 将数组从 android 传递到 php 在 android 4.1 上失败,但在 android 5+ 上成功

php - 即使在 php.ini 文件中进行更改,图像也不会上传

database - PostgreSQL 中的部分索引何时更新?

mysql - 从 SQL 查询问题下载 CSV

android - 如果我在另一台设备上安装该应用程序,是否仍然可以使用预制 ID 登录?

PHP PDO PostgreSQL -> 插入/更新日期或时间戳数组,以及 bool 值

php - MongoDB\BSON\ObjectID 在 MongoDB 的 JSON 编码中丢失

c++ - if 语句不比较我的字符串 c++ 中的数值