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

TMN*_*ear 5 php encryption sha1 sql-update

我正在使用SHA1来加密密码.在我的原始代码中,我检查了密码字段是否为空:if(空($ newpassword)和(空($ 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;
    }
Run Code Online (Sandbox Code Playgroud)

ale*_*lex 8

哈希之前检查输入.

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

CodePad.


Ign*_*tro 1

您可以检查密码字段是否不为空,方法是strlen()检查您实际发送的字符串的长度,因此如果字符串长于0,则它不为空,否则显示错误,告诉他们他们的密码密码字段为空,请勿将其添加到数据库中。此外,由于是加密哈希算法,因此无法转换SHA1回原始字符串SHA1,这将违背其背后的目的。散列和加密之间的主要区别在于,一种可以解密,另一种则不能。然而,这并不意味着SHA1哈希值不能被暴力破解,它们确实是容易的目标,但这MD5是该范围之外的另一个对话。