Programmaticly建设的htpasswd [英] Programmaticly building htpasswd

查看:215
本文介绍了Programmaticly建设的htpasswd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有建立一个编程方式的的htpasswd 的文件,而不依赖于操作系统的特定功能(即执行exec()中继())?

Is there a programmatic way to build htpasswd files, without depending on OS specific functions (i.e. exec(), passthru())?

推荐答案

.httpasswd文件与具体取决于指定的散列函数的特定格式只是​​文本文件。如果您使用的是MD5它们看起来是这样的:

.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:

foo:$apr1$y1cXxW5l$3vapv2yyCXaYz8zGoXj241

这就是登录,冒号,$ apr1 $,盐和1000次MD5 EN codeD为base64。如果您选择SHA1,他们是这样的:

That's the login, a colon, ,$apr1$, the salt and 1000 times md5 encoded as base64. If you select SHA1 they look like this:

foo:{SHA}BW6v589SIg3i3zaEW47RcMZ+I+M=

这就是登录,冒号,字符串{} SHA和SHA1哈希带的base64 codeD。

That's the login, a colon, the string {SHA} and the SHA1 hash encoded with base64.

如果你的语言有MD5或SHA-1和的base64你可以创建这样的文件的执行情况:

If your language has an implementation of either MD5 or SHA1 and base64 you can just create the file like this:

<?php

$login = 'foo';
$pass = 'pass';
$hash = base64_encode(sha1($pass, true));

$contents = $login . ':{SHA}' . $hash;

file_put_contents('.htpasswd', $contents);

?>

下面是关于格式的更多信息:

Here's more information on the format:

<一个href=\"http://httpd.apache.org/docs/2.2/misc/password_encryptions.html\">http://httpd.apache.org/docs/2.2/misc/password_encryptions.html

这篇关于Programmaticly建设的htpasswd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆