[英]How to generate .htpasswd under PHP
Im trying to generate long htpasswd file with a lot of users (100+). 我试图与许多用户(超过100个)生成较长的htpasswd文件。
My DirectAdmin panel on linux server generates htpasswd file with password hashes starting with $1$. 我在Linux服务器上的DirectAdmin面板生成htpasswd文件,其密码哈希值以$ 1 $开头。
I tried something like this: 我尝试过这样的事情:
function random_salt($length = 9) // 9 characters and $1$ = 12 characters
{
$chars = 'bcdfghjklmnprstvwxzaeiou';
for ($p = 0; $p < $length; $p++)
{
$result .= ($p%2) ? $chars[mt_rand(19, 23)] : $chars[mt_rand(0, 18)];
}
return $result;
}
echo crypt($myplainpassword, "$1$".random_salt());
It produces hash which starts with $1$, but server doesnt let me in. My passwords are 4-digit random "pin codes" generated in excel. 它产生以$ 1 $开头的哈希,但是服务器不允许我进入。我的密码是在excel中生成的4位随机“ pin码”。 Examples:
例子:
1215 5325 6261 1215 5325 6261
What im doing wrong? 我在做什么错?
This how I generate the .htpasswd passwords... 这就是我生成.htpasswd密码的方式...
$new_password = password_hash($old_password, PASSWORD_BCRYPT);
password_hash() creates a new password hash using a strong one-way hashing algorithm.
password_hash()使用强大的单向哈希算法创建新的密码哈希。 password_hash() is compatible with crypt().
password_hash()与crypt()兼容。 Therefore, password hashes created by crypt() can be used with password_hash().
因此,由crypt()创建的密码哈希可以与password_hash()一起使用。
The following algorithms are currently supported:
当前支持以下算法:
PASSWORD_BCRYPT - Use the CRYPT_BLOWFISH algorithm to create the hash.
PASSWORD_BCRYPT-使用CRYPT_BLOWFISH算法创建哈希。 This will produce a standard crypt() compatible hash using the "$2y$" identifier.
这将使用“ $ 2y $”标识符生成标准的crypt()兼容哈希。 The result will always be a 60 character string, or FALSE on failure.
结果将始终为60个字符串,否则为FALSE。 Supported Options:
支持的选项:
http://php.net/manual/en/function.password-hash.php http://php.net/manual/en/function.password-hash.php
I would recommend looking into the exact way how the hashes are generated. 我建议您仔细研究散列的产生方式。 If you create a hash using your method, does it look the same as the one generated by DirectAdmin?
如果使用方法创建哈希,它看起来与DirectAdmin生成的哈希相同吗?
In general, I have previously used this to generate the entries. 通常,我以前曾用它来生成条目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.