简体   繁体   English

如何使用php为htpasswd文件生成密码

[英]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.

相关问题 如何在.htpasswd文件中补充密码 - How to makeup password in .htpasswd file 如何在PHP下生成.htpasswd - How to generate .htpasswd under PHP 如何使用 php 生成.htpasswd 密钥,我可以将其插入到我的 ubuntu 服务器上的 my.htpasswd 文件中? - How to generate .htpasswd keys with php that I could insert into my .htpasswd file on my ubuntu server? 使用.htpasswd保护文件夹,但允许在保护密码的同时下载php - Protecting folder using .htpasswd, but allowing php download while protecting password 如何使用php生成受密码保护的csv文件 - How to generate password protected csv file by using php PHP-带有curl,如何在htpasswd的弹出窗口中发送用户名密码? - PHP - with curl, how to send username password in a popup of htpasswd? 如何使用 PHP 验证 htpasswd 生成的 bcrypt hash? - How to verify a htpasswd-generated bcrypt hash using PHP? PHP:fopen检查客户端是否已使用密码保护的文件(htpasswd)进行身份验证 - PHP: fopen to check whether client has authenticated with a password protected file (htpasswd) 使用盐的.htpasswd密码进行apache身份验证 - apache authentication with .htpasswd password using salt 使用.htaccess和.htpasswd保护单个页面的密码 - Password protecting a single page using .htaccess and .htpasswd
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM