In order to protect a directory on an Apache HTTPD web server with a password, this configuration was added to an .htaccess file in the respective directory:
AuthType Basic AuthName "Protected Directory" AuthUserFile /var/www/dir/ .htpasswd Require valid-user
Furthermore, a file /var/www/dir/ .htpasswd was created with the following content:
Given that all these files were correctly processed by the web server processes, which of the following statements is true about requests to the directory?
A. The user usera can access the site using the password S3cr3t
B. Accessing the directory as usera raises HTTP error code 442 (User Not Existent)
C. Requests are answered with HTTP error code 500 (Internal Server Error)
D. The browser prompts the visitor for a username and password but logins for usera do not seem to work
E. The web server delivers the content of the directory without requesting authentication
题解
「.htpasswd」文件中的密码字段,如果使用「htpasswd」指令来产生的话,虽然预设并不会以明码保存,但是可以透过提供「-p」参数来使用明码。不过,Apache HTTP 服务器只有在 Windows 和 NetWare 上才接受明码的密码,在 Linux 上是无法用明码来验证的。
「htpasswd」指令预设会使用 MD5 进行哈希(「-m」参数),「.htpasswd」文件看起来会像这样:
如果要更安全的话,通常会使用 bcrypt 来进行哈希(「-B」参数),「.htpasswd」文件看起来会像这样:
从题目提供的「.htpasswd」文件,可以看出它是使用明码来保存密码。
而「Require」设置为「valid-user」的话,任何存在于「.htpasswd」文件中的用户才可以透过提供正确的密码来访问文件资源。如果用户密码验证失败的话,会回传 HTTP 的 401 状态(Authorization Required)。这题的「.htpasswd」文件是用明码来保存密码,在 Linux 上的 Apache HTTP 服务器并不接受,所以浏览器虽然会要求输入用户名和密码,但「usera」就算输入「S3cr3t」也无法通过验证。
因此选项「D」是正确答案。
