-3

出于某种原因,我无法让我的函数返回一个字符串......

$password = crypt_password_input($password, "");

//Encrypt Password longer than 8 characters
function crypt_password_input($inputPassword, $newPassword)
{
    $passwordLength = strlen($inputPassword);

    if($passwordLength > 8){
        $encryptString = substr($inputPassword, 0, 8);
        $inputPassword = substr($inputPassword, 8);
        $newPassword .= crypt($encryptString, "HIDDENSALT");
        crypt_password_input($inputPassword, $newPassword);
    }else{
        $newPassword .= crypt($inputPassword, "HIDDENSALT");
        echo "Final: " . $newPassword . "<br/>";
        return $newPassword;
    }
}


echo "Encrypted from the input: " . $password . "<br/>";

这是这个脚本的输出......

最终:ltu1GUwy71wHkltVbYX1aNLfLYltEZ7Ww8GghfM
从输入加密:

4

2 回答 2

3

return您在此条件块下没有声明。我在那里添加了回报。

if($passwordLength > 8)
{
    $encryptString = substr($inputPassword, 0, 8);
    $inputPassword = substr($inputPassword, 8);
    $newPassword .= crypt($encryptString, "HIDDENSALT");
    return crypt_password_input($inputPassword, $newPassword);
}
于 2013-08-05T07:49:29.467 回答
0

我不确定你的逻辑,但你的代码应该是这样的:

$password = crypt_password_input($password, "");

//Encrypt Password longer than 8 characters
function crypt_password_input($inputPassword, $newPassword)
{
    $passwordLength = strlen($inputPassword);

    if($passwordLength > 8)
    {
        $encryptString = substr($inputPassword, 0, 8);
        $inputPassword = substr($inputPassword, 8);
        $newPassword .= crypt($encryptString, "HIDDENSALT");
        return crypt_password_input($inputPassword, $newPassword);
    }
    else
    {
        $newPassword .= crypt($inputPassword, "HIDDENSALT");
        echo "Final: " . $newPassword . "<br/>";
        return $newPassword;
    }
}


echo "Encrypted from the input: " . $password . "<br/>";

在您的代码中,您递归调用输入但不返回任何内容,因此如果您的密码长度超过 8 个字符,则会失败。

于 2013-08-05T07:49:37.780 回答