php - 如何在 .htpasswd 文件中使用 md5 密码?

标签 php .htaccess .htpasswd

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

最佳答案

Documentation说:

htpasswd encrypts passwords using either a version of MD5 modified for Apache, or the system's crypt() routine. Files managed by htpasswd may contain both types of passwords; some user records may have MD5-encrypted passwords while others in the same file may have passwords encrypted with crypt().

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

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

$clearTextPassword = 'some password';
$password = crypt($clearTextPassword, base64_encode($clearTextPassword));

关于php - 如何在 .htpasswd 文件中使用 md5 密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11815121/

相关文章:

php - 使用最新的 PHP 语法是否有任何性能提升?

apache - .htaccess 中的条件目录索引

.htaccess - 重定向到 HTTPS 返回错误 "too many redirects"

security - nginx auth_basic 是否发送明文密码?

php - .htaccess 受密码保护的文件夹转到 404 页面

htpasswd 身份验证后,php 文件不会呈现

php - http从服务器到服务器传输文件

php - 在 multistore .htaccess 之后,Magento 中的类别 View (仅)缺少产品

PHP array_intersect() 直到第一个匹配

.htaccess - htaccess seo url 对\and/友好