dongwei6700 2014-08-20 19:14
浏览 14
已采纳

无数据库认证(PHP)

How to securely authenticate a user without using any type of database.

authenticate.php?username={$_GET['username']}&password={$_GET['password']}


if ($_GET['username'] == "secret_username" && password == "secret_password")
{
   $_SESSION['user'] = $username;
   header("Location: password_protected_page.php");
   exit;
}

This method seems to be an option. Is it secure?

  • 写回答

4条回答 默认 最新

  • douwen5924 2014-08-20 19:21
    关注

    Use a file to hold your data. have a users.txt below your public html like so:

    username:hashedpassword

    then you use fopen

    <?php
    
        $filename = "/home/users.txt";
        $file = fopen( $filename, "r" );
        $display = fread( $file, filesize( $filename ) );
        fclose($file);
    
    ?>
    

    Then explode it by newline and then |, then check if the first is equal to username and the second is equal to md5(password).

    Seems like the easiest way to me...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?