Is there a programmatic way to build htpasswd files, without depending on OS specific functions (i.e. exec()
, passthru()
)?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Trac ships with a Python replacement for htpasswd, which I'm sure you could port to your language of choice: htpasswd.py.
.httpasswd files are just text files with a specific format depending on the hash function specified. If you are using MD5 they look like this:
That's the login, a colon, ,$apr1$, the salt and 1000 times md5 encoded as base64. If you select SHA1 they look like this:
That's the login, a colon, the string {SHA} and the SHA1 hash encoded with base64.
If your language has an implementation of either MD5 or SHA1 and base64 you can just create the file like this:
Here's more information on the format:
http://httpd.apache.org/docs/2.2/misc/password_encryptions.html
From what it says on the PHP website, you can use crypt() in the following method:
Part of this example can be found: http://ca3.php.net/crypt
This will of course overwrite the entire existing file, so you'll want to do some kind of concatination.
I'm not 100% sure this will work, but I'm pretty sure.