2009-12-31 57 views

回答

1

最好委託htpasswd應用程序system()等而不是自己推出。

另請考慮使用數據庫和mod_auth_mysql或類似的身份驗證。

1

這裏的鏈接

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; 
?> 

請注意:對於Windows上運行的Apache服務器,你必須使用htpasswd的程序生成的密碼,或使用htpasswd的發電機。

0

這對我有效。

$new_password = password_hash($old_password, PASSWORD_BCRYPT); 

password_hash()創建使用強單向 散列算法一個新的密碼哈希。 password_hash()與crypt()兼容。 因此,由crypt()創建的密碼哈希可以與 password_hash()一起使用。

(...)

PASSWORD_BCRYPT - 使用算法crypt_blowfish的創建哈希值。 這將使用「$ 2y $」 標識符生成標準crypt()兼容散列。結果將始終爲60個字符的字符串,如果失敗,則結果將爲FALSE 。支持的選項:

http://php.net/manual/en/function.password-hash.php