【发布时间】:2018-12-28 18:31:26
【问题描述】:
我有一个运行只读会员提供程序的旧应用程序。我的任务是创建一个管理页面来帮助从这个应用程序添加/更改/删除用户。会员提供者使用FormsAuthentication,我无法使用它,因为我的管理应用程序位于 .net Core 中。我正在尝试对他们使用FormsAuthentication 加密的方式进行逆向工程,到目前为止我有这个:
他们使用:
FormsAuthentication.HashPasswordForStoringInConfigFile(password, "sha1").ToLower();
我已经对其进行了逆向工程:
(传入字符串pwd)
HashAlgorithm hashAlgorithm = new HMASHA1();
var step1 = Encoding.UTF8.GetBytes(pwd);
var step2 = hashAlgorithm.ComputeHash(step1);
var step3 = BinaryToHex(step2);
第 3 步的结果类似于“AD626B9D42073B299ECFC664CCB7A8B01F3AF726”,看起来就像旧应用程序的 XML 用户文件中的密码一样。
我很好奇如果我使用这种散列方法(适用于 .net 核心),散列后的密码是否能够被FormsAuthentication“验证”?
到目前为止,我的测试似乎没有奏效。有任何想法吗?我做错了吗?
编辑:它不是 HMASHA1,它是 SHA1Cng - 我不能使用它,因为它在 .net 框架的 System.Core 中 4.something...我可以在 .net 核心中使用什么来执行此操作?
【问题讨论】:
-
试试
var newPassword=_userManager.PasswordHasher.HashPassword(user,newpass);。如果默认哈希不适合你,你也可以参考source code here
标签: asp.net-core hash passwords forms-authentication