Htaccess 身份验证

Htaccess authentication

我有一个主机,在那里我有指定的管理面板。在这个面板上,我可以设置密码和用户名,密码会被加密。所以我的问题是: 有什么方法可以设计身份验证吗?

我的意思是,当它需要登录名和密码时,它会在浏览器中弹出,我想在网站上实现这一点,我可以用 CSS 设计它,而不是在浏览器。有什么想法吗?

提前致谢,任何有用的答案都让我更接近。

首先,请注意,如果您使用 "Basic Authentication" 且未使用 ssl 模块包装,则用户名和密码将以明文(base64 编码)文本形式发送。

要实现您的目标,您必须使用 "form authentication":

<form method="post" action="validate_credentials.php" >
  <table border="1" >
     <tr>
        <td><label for="user">Username</label></td>
        <td><input type="text" name="user" id='user'></td>
     </tr>
     <tr>
        <td><label for="pass" >Password</label></td>
        <td><input name="pass" id='pass' type="password" ></input></td>
      </tr>
      <tr>
         <td><input type="submit" value="Submit"/></td>
      </tr>
  </table>
</form>

下面是 validate_credentials.php 文件的样子:

<?php

// Grab User submitted information
$username = $_POST["user"];
$password = $_POST["pass"];

// Stored user name and password
$db_user = "secret_username";
$db_pass = "secret_password";

// Authentication mechanism

if ($username != $db_user and $password != $db_pass) {
     echo"Invalid Credentials, Please try again.";
     exit();
}

if ($username == $db_user and $password == $db_pass) {
    echo"Valid Credentials, You are authenticated.";
    // You can now serve the document that was requested.
}

我只是尽量保持简单,以便您理解。为了安全起见,请验证用户输入并且不要在 validate_credentials.php 文件中使用明文密码,您可以 google 如何做到这一点。