简体   繁体   English

使用盐的.htpasswd密码进行apache身份验证

[英]apache authentication with .htpasswd password using salt

I am wondering how the Apache server authenticates me with .htpasswd 我想知道Apache服务器如何通过.htpasswd我进行身份验证

I have a .htpasswd file inside a folder. 我在文件夹中有一个.htpasswd文件。 The .htpasswd content is generated with php and the password is encrypted with the crypt() function like this: .htpasswd内容是用php生成的,密码是使用crypt()函数加密的,如下所示:

crypt($password,mb_substr($password,0,2));

The problem is that no matter which salt I use: mb_substr($password,0,2) or my_private_salt or 'whatever' the server will always authenticate me if I pass the correct username/password combination. 问题是,无论我使用哪种盐: mb_substr($password,0,2)my_private_salt或“无论如何”,如果我通过正确的用户名/密码组合,服务器将始终对我进行身份验证。

So, what's the point with that salt? 那么,那盐有什么意义呢?

Thanks 谢谢

I found the answer. 我找到了答案。

The php crypt() function generates a unique hash. php crypt()函数生成唯一的哈希。 If the salt is not specified then a random salt will be generated. 如果未指定盐,则将生成随机盐。

A BIG problem is that only the first 8 characters from the password will be used to generate the hash and only two characters from the salt. 一个大的问题是,密码中只有前8个字符将用于生成哈希,而盐中只有两个字符。

The resulting hash will be composed of the salt + another 11 characters. 所得的哈希将由salt +另外11个字符组成。

For example: if we do: crypt('1234567','12') the result will be "120QBxD1IX.Cw". 例如:如果执行:crypt('1234567','12'),结果将为“ 120QBxD1IX.Cw”。 Notice the first two characters from the hash (12) 注意哈希中的前两个字符(12)

This is how the Apache server will know how to encrypt the request and compare it with the saved hash in the .htpasswd file. 这就是Apache服务器知道如何加密请求并将其与.htpasswd文件中保存的哈希进行比较的方式。

For a better explanation please see this link: http://blog.irreverence.co.uk/?p=858 有关更好的解释,请参见以下链接: http : //blog.irreverence.co.uk/?p=858

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM