7

我的问题

为什么 .htaccess 和 .htpasswd 不接受我的登录信息?

我的资源来了解我应该做什么

  1. http://www.addedbytes.com/blog/code/password-protect-a-directory-with-htaccess/
  2. http://www.elated.com/articles/password-protecting-your-pages-with-htaccess/

我做了什么?

我从phpinfo()

我的根目录的完整路径:/home/userid/public_html

我将 .htpasswd 放入根文件夹 (public_html) 中,因此我的 .htpasswd 的完整路径:/home/userid/public_html/.htpasswd

我想通过密码保护的管理文件夹名称:adminfolder

我把我的adminfolder放入根文件夹(public_html)

文件夹结构

public_html
---- .htaccess {permission: -rw-r--r--}
---- .htpasswd {permission: -rw-r--r--}
---- adminfolder {permission: drwxr-xr-x}
---- ---- .htaccess {permission: -rw-r--r--}
---- ---- other secret files {permission: -rw-r--r--}

.htaccess 代码(adminfolder 中的那个)

AuthUserFile /home/userid/public_html/.htpasswd
AuthName "Log In"
AuthType Basic
Require valid-user

.htpasswd 代码

注意:这是我的原始密码的加密版本。

admin:zv.sqVSz3W1nk

.htaccess 代码(public_html 中的那个)

RewriteEngine On
RewriteBase /

#always use www - redirect non-www to www permanently
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


# hotlink protection
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?domain.p.ht [NC]
RewriteRule \.(jpg|jpeg|png|gif|css|js)$ - [NC,F,L]

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# File caching is another famous approach in optimizing website loading time
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>

# disable directory browsing
Options All -Indexes

# secure htaccess file
<Files .htaccess>
 order allow,deny
 deny from all
</Files>

# secure spesific files
<Files a_secret_file.php>
 order allow,deny
 deny from all
</Files>

#SEO friendly linking
...
...

我检查了

  1. 我的完整路径信息
  2. 用户名 - 原始密码和加密密码
  3. 编码
  4. 我所有的文件都是用记事本++和编码的 UTF-8 准备的,没有 BOM

最后

我试过铬。我输入了用户名 + 未加密的原始密码。Chrome 要求我再次登录。

然后我清除了 IE 的所有缓存。我再次输入用户名+非加密密码。IE还要求我再次登录。

你能纠正我吗?谢谢,BR

4

2 回答 2

6

这个问题是因为您的服务器可能使用不同的算法来加密/解密密码,您可以测试不同算法的不同密码组合以找出正确的密码。

请看这个网站:http ://aspirine.org/htpasswd_en.html

它使用 JavaScript 生成密码,出于安全原因,您可以保存页面并在本地运行它。

请检查Apache htpasswd

于 2013-04-03T11:56:51.310 回答
2

注意:这是我的原始密码的加密版本。管理员:zv.sqVSz3W1nk

Unix http 服务器会将其解释为 crypt(3) 散列密码,但 windows/netware 上的 apache 会将其解释为明文密码。但我猜你的服务器是 Unix 的,所以这可能不是问题。

我所有的文件都是用记事本++和编码的 UTF-8 准备的,没有 BOM

您的密码是否包含一些非 ASCII 字符,例如法语口音?如果您想保持简单和跨浏览器兼容,请仅使用 7 位 ASCII 字符。看到这个问题

于 2013-07-31T22:14:11.413 回答