[英]how to generate a password for htpasswd file using php
Hi how can i generate a password using php, to use for the htpasswrd file. 嗨,我如何使用php生成密码,以用于htpasswrd文件。 which encoding we are using? 我们正在使用哪种编码?
It's better to delegate to the htpasswd
app with system()
and the like rather than to roll your own. 最好使用system()
之类的东西委托给htpasswd
应用,而不是自己动手。
Also consider using a database and mod_auth_mysql or similar for auth. 还可以考虑使用数据库和mod_auth_mysql或类似的auth。
here the link 这里的链接
http://www.htaccesstools.com/articles/create-password-for-htpasswd-file-using-php/ http://www.htaccesstools.com/articles/create-password-for-htpasswd-file-using-php/
<?php
// Password to be encrypted for a .htpasswd file
$clearTextPassword = 'some password';
// Encrypt password
$password = crypt($clearTextPassword, base64_encode($clearTextPassword));
// Print encrypted password
echo $password;
?>
Please note: For Apache servers running on Windows you have to use the htpasswd program to generate passwords, or use the htpasswd generator. 请注意:对于在Windows上运行的Apache服务器,您必须使用htpasswd程序来生成密码,或者使用htpasswd生成器。
This worked for me. 这对我有用。
$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()一起使用。
(...) (......)
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.