2

您好我正在尝试设置一个.htaccess和一个.htpasswd文件以查看用户是否可以访问特定目录。当新用户注册时,他们的密码使用 PHPmd5()函数加密,然后与其他登录信息一起存储在数据库中。我想将他们的一些加密密码.htpasswd动态添加到我的文件中,以便他们可以进入子成员部分。我遇到了麻烦,因为该.htpasswd文件可以使用使用该crypt()功能加密的密码,但我不确定如何让它使用他们的 md5 加密密码。

4

2 回答 2

6

文档说:

htpasswd 使用为 Apache 修改的 MD5 版本或系统的 crypt() 例程来加密密码。htpasswd 管理的文件可能包含两种类型的密码;某些用户记录可能具有 MD5 加密的密码,而同一文件中的其他用户记录可能具有使用 crypt() 加密的密码。

-m我认为您可以使用参数明确指定 apache 在 htpasswd 文件中使用 md5s 作为密码htpasswd

如果您不想或不能使用 htpasswd 工具,您可以从 PHP创建基于crypt()的密码:

$clearTextPassword = 'some password';
$password = crypt($clearTextPassword, base64_encode($clearTextPassword));
于 2012-08-05T08:57:19.773 回答
3

"I think you can explicitly specify apache to use md5s for password in htpasswd file using -m argument to htpasswd"

I just found out the exact opposite in Ubuntu 12.04 and newer, it defaults to md5 and you have to use the -d flag to get it to use Crypt. This might be the case elsewhere too, I can't seem to find a version number for htpasswd.

于 2012-11-03T22:48:21.697 回答