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