php - 使用 SHA1 时如何检查 PHP 字段是否为空

标签 php encryption sql-update sha1

我正在使用 SHA1 加密密码。在我的原始代码中,我检查了密码字段是否为空:if (empty($newpassword) and (empty($newpassword2))) { }

由于我现在使用 SHA1,当字段留空时它会自动生成 da39a3ee5e6b4b0d3255bfef95601890afd80709,我该如何重写我的代码?

将 da39a3ee5e6b4b0d3255bfef95601890afd80709 翻译回字符串?还是别的?

请帮忙。

    if ($_SERVER['REQUEST_METHOD'] == 'POST')
    {
        // oude password controle
        if ($password == $qpassword)
            $oudpassword_goed = 1;
        // password controle
        if ($newpassword == $newpassword2)
            $newpassword_goed = 1;
        if (empty($newpassword) and (empty($newpassword2)))
            $newpassword_goed = 2;
        // email controle
        if ($email == $email2)
            $email_goed = 1;
    }

最佳答案

只需在对输入进行哈希处理之前检查它。

此外,不要使用 empty()。这将告诉您用户输入了一个密码,如果他们的密码是0(当然,您不允许只有一个字符的密码,对吧?)

CodePad .

关于php - 使用 SHA1 时如何检查 PHP 字段是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12913873/

相关文章:

MySQL:更新触发器。如果不匹配任何行,获取 UPDATE 的 where 子句中使用的列的值?

mysql - 在 mySQL 中使用多个结果更新内连接的值

php - 我如何在 URL 中实现 escapeshellarg?

PHP 表单字段(显示 :none) Spam Prevention

php - 如何在PHP中实现一个可以接受任意参数的函数?

ios - 加密/解密 .plist 文件 ios

encryption - 为什么我的 crypto.createHmac() 会为相同的输入生成不同的 HMAC?

java - 使用 RSA 解密字符串会在开头返回额外的零

javascript - 将类添加到点击的模态

mysql - sql查询根据2个表中的值更新字段