1

男ああ、私はこれを理解することはできません.助けてください. ここに何が欠けているのですか?

エラーは次のとおりです。

Notice: Uninitialized string offset: 62 in /..../libraries/functions.php on line 316
Notice: Undefined variable: stilldo in /..../libraries/functions.php on line 322

コードは次のとおりです。

function generate_password($length = 12, $letters = true, $mixed_case = true, $numbers = true, $punctuation = false){

    ## Generate the alfa
    $alfa = '';
    if($letters == true)    $alfa .= 'abcdefghijklmnopqrstuvwxyz';
    if($mixed_case == true) $alfa .= strtoupper('abcdefghijklmnopqrstuvwxyz');
    if($numbers == true)    $alfa .= '0123456789';
    if($punctuation == true)$alfa .= '~!@#$%^&*(),.=+<>';

    ## Set Random Seed
    if(!function_exists('_generate_password_seed')):
    function _generate_password_seed(){
        list($usec, $sec) = explode(' ', microtime());
        return (float) $sec + ((float) $usec * 100000);
    }
    endif;
    srand(_generate_password_seed());

    ## Generate the password
    $token = "";
    for($i = 0; $i < $length; $i ++) {
        $token .= $alfa[@rand(0, @strlen($alfa))];
    }

    ## Check the length
    if(strlen($token) < $length){
        // echo $stilldo = $length - strlen($token);
        $token .= generate_password($stilldo);
    }

    ## Return the password
    return $token;
}

この関数を実行すると 10 回中 5 回このエラーが発生しますが、クラックできないようです。

4

1 に答える 1

0

Notice: Undefined variable: stilldo変数$stilldoが定義されておらず、初期化されていないことを意味します...つまりgenerate_password、実際にはnull値を持つ未定義の変数を渡すときに、関数を再帰的に呼び出すことを意味します。したがって、あなたの機能は正しく動作しません。

コードの一部は次のようになります。

## Check the length
if(strlen($token) < $length){
    $stilldo = $length - strlen($token);
    $token .= generate_password($stilldo);
}

はい、ばかげた間違いです-正しい行をコメントアウトしました(echoコメントアウトまたは削除する必要がある場所のみ)。

楽しみ!

于 2012-04-24T09:55:00.970 に答える