apache htdigest 文件格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/394552/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
htdigest file format
提问by wxs
I'm trying to write some code to work with an htdigest password file. The documentation I can find seems to claim that the format of that file is:
我正在尝试编写一些代码来处理 htdigest 密码文件。我能找到的文档似乎声称该文件的格式是:
user:realm:MD5(user:realm:pass)
If that is the case, then why doesn't this work for me? I created a file with the command line htdigest thus:
如果是这样,那为什么这对我不起作用?我使用命令行 htdigest 创建了一个文件,因此:
htdigest -c test b a
When prompted for a password I entered 'c'. This creates a file with the contents:
当提示输入密码时,我输入了“c”。这将创建一个包含以下内容的文件:
a:b:02cc8f08398a4f3113b554e8105ebe4c
However if I try to derive this hash I can't,
但是,如果我尝试导出此哈希值,则无法导出,
echo a:b:c | md5
gives me "49d6ea7ca1facf323ca1928995420354". Is there something obvious that I'm missing here?
给我“49d6ea7ca1facf323ca1928995420354”。有什么明显的东西我在这里失踪了吗?
Thanks
谢谢
回答by James Brady
echoby default adds a trailing new line:
echo默认情况下添加一个尾随新行:
echo -n a:b:c | md5
Should work as you expect.
应该按您的预期工作。
回答by wxs
Hm, I seem to have answered my own question. My test case was flawed, 'echo' is adding extra characters (not sure which). For instance
嗯,我好像已经回答了我自己的问题。我的测试用例有缺陷,'echo' 正在添加额外的字符(不确定是哪个)。例如
echo a:b:c | wc
gives 6 characters instead of 5. Calculating the hash at http://md5-hash-online.waraxe.us/gives the correct value. Sorry everyone!
给出 6 个字符而不是 5 个。在http://md5-hash-online.waraxe.us/计算散列给出正确的值。对不起大家!
回答by wxs
Here is how you set the password for a given user.
以下是为给定用户设置密码的方法。
sudo htdigest /etc/apache2/.htdigest yourrealm.com yourusername

