简体   繁体   English

在ASP.net中复制PHPBB密码哈希c#

[英]Replicate PHPBB password hashing in ASP.net c#

I'm using phpbb 3.0.8 at the moment. 我现在正在使用phpbb 3.0.8。 It has 3,000 users and around 60,000 posts. 它拥有3,000名用户和约60,000个帖子。 I'm changing the forum to a different one, written in classic ASP (I know people are going to disapprove of this but I have good reasons). 我正在将论坛改为另一个,用经典的ASP编写(我知道人们会对此不赞成,但我有充分的理由)。

My site is written in ASP.net. 我的网站是用ASP.net编写的。 The classic ASP forum has an API to connect to it. 经典的ASP论坛有一个连接它的API。 I've set all this up, and it works fine. 我把所有这些都设置好了,它运行正常。 I have written my own login form. 我已经写了自己的登录表单。

I want to copy all the user accounts over. 我想要复制所有用户帐户。 The current forum has the table: 目前的论坛有表:

Username | Password |  Hash  |  Salt

I've overidden the classic ASP hashing technique to now use the ASP.net Security.SHA1 hash. 我已经覆盖了经典的ASP哈希技术,现在使用ASP.net Security.SHA1哈希。 The password is stored as SHA1(rawpassword + salt) . 密码存储为SHA1(rawpassword + salt)

My plan is to store new fields along side the current ones: 我的计划是将新字段存储在当前的字段旁边:

UserID | Password |  Hash  |  Salt  |  PHPBBHash

When the user logs in, if the PHPBB hashh field is set, it hashes the password with the PHPBB hash. 当用户登录时,如果设置了PHPBB hashh字段,则使用PHPBB哈希散列密码。 Then, if login is sucessful, it deletes the PHPBBHash field, and creates the current systems hash values. 然后,如果登录成功,它将删除PHPBBHash字段,并创建当前系统哈希值。 This way, it's a smooth transition over from PHPBB to the new forum, and no one loses their accounts. 这样,这是从PHPBB到新论坛的平稳过渡,没有人丢失他们的帐户。

My problem is, given a PHPBB hash, a username, and password, in ASP.net c# how can I verify the PHPBB hash? 我的问题是,给定PHPBB哈希,用户名和密码,在ASP.net中c#如何验证PHPBB哈希? How does it calculate it? 它是如何计算的?

My concern is also that the classic ASP hash function claimed to be SHA1, but it produced different results to Securiy.SHA1 . 我担心的是经典的ASP哈希函数声称是SHA1,但它产生了与Securiy.SHA1不同的结果。

Edit 编辑

I've put a bounty on this if anyone can give me a definitive solution, I appreciate the answer linking to the resources but I'm still struggling to understand it. 如果有人能给我一个明确的解决方案,我会对此表示赏心悦目,我很欣赏链接到资源的答案,但我仍然在努力理解它。

Test Case 测试用例

Raw password: 原始密码:

blingblangblaow222

In PHPBB3 database: 在PHPBB3数据库中:

username: Tom
username_clean: tom
user_password: $H$9ojo08A3LuhnkXR27p.WK7dJmOdazh0
user_passchg: 1301433947
user_form_salt: 637f480dfdab84ef

Using the example code from Vishalgiris answer, we do this: 使用来自Vishalgiris的示例代码回答,我们这样做:

phpBB.phpBBCryptoServiceProvider cPhpBB = new phpBB.phpBBCryptoServiceProvider();
string remoteHash = "$H$9ojo08A3LuhnkXR27p.WK7dJmOdazh0";
bool result = cPhpBB.phpbbCheckHash("blingblangblaow222", remoteHash);
Response.Write("<BR><BR><BR>" + result);

This actually returns true. 这实际上返回true。 Super! 超! But does anyone know why this works? 但有谁知道为什么这有效? I'm baffled, it doesn't seem to take salt into account at all. 我很困惑,它似乎根本不考虑盐。

It appears that PHPBB verifies passwords via the phpbb_check_hash function in the functions.php source file . 似乎PHPBB通过functions.php源文件中phpbb_check_hash函数验证密码。 It looks like it typically relies on _hash_crypt_private to do the real work. 看起来它通常依赖于_hash_crypt_private来完成真正的工作。 The function is 57 lines long (including plenty of whitespace), so it should be relatively straight-forward to convert it to C#. 该函数长57行(包括大量的空格),因此将其转换为C#应该相对简单。

Seems like your answer is here at phpBB community , however as you already know, it is salted hash so you need to use the function provided in the link to check your password, because the hash will change whenever generated. 似乎你的答案就在phpBB社区 ,但是你已经知道,它是盐渍哈希所以你需要使用链接中提供的功能来检查你的密码,因为哈希会随着生成而改变。

Please ignore if you already tried the code provided in the link. 如果您已经尝试过链接中提供的代码,请忽略。

Hope it helps... 希望能帮助到你...


One more option would be to create seperate php page/service, to do password hashing or hash validation. 还有一个选择是创建单独的php页面/服务,进行密码散列或散列验证。 to create has use "phpbb_hash" function and to check use "phpbb_check_hash" and these functions can be exposed to ASP or ASP.NET via a page or service. 创建使用“phpbb_hash”函数并检查使用“phpbb_check_hash”,这些函数可以通过页面或服务公开给ASP或ASP.NET。

You can also tweak the current Phpbb system so that it stores a SHA1 hash of the password entered during login. 您还可以调整当前的Phpbb系统,以便它存储登录期间输入的密码的SHA1哈希值。 If you run with this tweak a while, you will have most active users covered and that saves you the trouble of implementing the complex algorithm. 如果您使用此调整运行一段时间,您将覆盖大多数活动用户,这将为您节省实施复杂算法的麻烦。 The not so active users can just request a new password when they can't login, or you could all give them a new password and mail it to them (you can select them on the last login date stored in the Phpbb database). 不太活跃的用户只能在无法登录时请求新密码,或者您可以向他们提供新密码并将其邮寄给他们(您可以在存储在Phpbb数据库中的最后登录日期选择它们)。

Depending on your needs, you might also want to cover the auto login facility of Phpbb. 根据您的需要,您可能还想要涵盖Phpbb的自动登录功能。 Users that use this feature might not even know their passwords and thus they will have trouble logging into your new system if it does not support auto login. 使用此功能的用户可能甚至不知道他们的密码,因此如果它不支持自动登录,他们将无法登录到您的新系统。

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

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