【解決方法】PHPガンスタはどのように機能しますか?


こんにちは、PHPギャングスタを使用して2faを使用しようとしています
GitHub – PHPGangsta/GoogleAuthenticator: Google Authenticator 2 要素認証を生成および検証するための PHP クラス[^]

しかし、私はそれを実装する方法や、それがどのように機能するかさえ理解していません。
これは私のスクリプトです:
ご覧のとおり、loginback.php に php ギャングスタを追加しましたが、ここに私の質問があります。
1)ここQRコードは関係ない? 私のように、ユーザーが登録するときだけそれを使用する必要がありますか? 彼らは常にそのQRコードをGoogleアプリに持っていますか?
2) 暗証番号とは? cuz は、Google 認証アプリにあるものと常に異なるわけではありませんか?
3) 私のコードはどのようにして Google 認証コードを認識しますか?
4) ユーザー入力コードが gthe と同じであることをどのように確認しますか?

google authenticator code?

script = login_back.php
<pre>session_start();

if ( !isset($_POST['email'], $_POST['password']) ) {
    // Could not get the data that should have been sent.
    exit('Please fill both the username and password fields!');
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') { 
    require_once '../PHPGangsta/GoogleAuthenticator.php';

    $ga = new PHPGangsta_GoogleAuthenticator();
    $secret = $ga->createSecret();
    echo "Secret is: ".$secret."\n\n";
    echo "<br>";
    if(!empty($_POST['code'])){
        $code = $_POST['code'];
        if($ga->verifyCode($secret, $code)){
            echo "correct";
        }else{
            echo "fout";
        }
        
        $result = $ga->verifyCode($secret, $code, 3);
        echo "test";
        echo $result;
    }
    echo "<br>";
    $qrCodeUrl = $ga->getQRCodeGoogleUrl( 'glasvezel', $secret);
    echo '<img src="'.$qrCodeUrl.'" /><br />';


    // $code = $_POST['code'];
    // echo "code user has entered ".$code;

    echo "<br>";
    $oneCode = $ga->getCode($secret);
    echo "Checking Code '$oneCode' and Secret '$secret':\n";

    //code verificeerd alleen de secret en one code??
    $checkResult = $ga->verifyCode($secret, $oneCode, 3);    // 2 = 2*30sec clock tolerance
    echo "<br>";
    echo $checkResult;
    echo "<br>";
    if ($checkResult) {

        include "../config.php";
        $email = $_POST['email'];
        $password = $_POST['password'];

            $sql = 'SELECT * FROM users WHERE email = ?';
            $stmt = $conn->prepare($sql); 
            $stmt->bind_param("s", $email);
            $stmt->execute();
            $result = $stmt->get_result(); // get the mysqli result
            if ($row = $result->fetch_assoc()) {
                $naam = $row['name'];
                    // Account exists, now we verify the password.
                    // Note: remember to use password_hash in your registration file to store the hashed passwords.
                    
                    if (password_verify($password, $row['password'])) {
                        // Verification success! User has logged-in!
                        // Create sessions, so we know the user is logged in, they basically act like cookies but remember the data on the server.
                        session_regenerate_id();
                        $_SESSION['loggedin'] = TRUE;
                        $_SESSION['name'] = $naam;
                        // $_SESSION['id'] = $id;
                        echo 'Welcome ' . $_SESSION['name'] . '!';
                        
                    } else {
                        // Incorrect password
                        echo "<script>
                        alert('Verkeerd username of password');
                        window.location.href='../admin/login.php';
                        </script>";
                    }
                $stmt->close();
        }else{
            echo "<script>
                        alert('verkeerd email ingevoerd');
                        window.location.href='../admin/login.php';
                        </script>";
        }

    } else {
        echo 'FAILED';
    }
}

    

?>

私が試したこと:

私はグーグルで検索しましたが、コードに追加すると言うだけで動作します???

解決策 1

作成者に相談してください。上部に「問題」ボタンがあり、問題を説明するメッセージを投稿できます。 課題 · PHPGangsta/GoogleAuthenticator · GitHub[^]

しかし… それは 4 年間変更されていない 10 年前のプロジェクトです。 Google Authenticator の変更により最新ではない可能性があり、それが問題になる可能性があります。

コメント

タイトルとURLをコピーしました