gpt4 book ai didi

c# - 从 C# 到 MySQL CakePhp 用户的身份验证

转载 作者:太空宇宙 更新时间:2023-11-03 21:52:56 25 4
gpt4 key购买 nike

我目前正在将 CakePhp 应用程序迁移到 ASP.NET。在这一点上阻碍我的一件事是我无法获得正确的哈希方法来获得正确的密码,以便用户能够从 ASP.NET 应用程序登录。

我在 config/core.php 文件中设置了盐值。

我用谷歌搜索试图确定在哪里可以找到使用了哪种哈希算法,但找不到正确的查询或找不到结果。

这是我目前为止对密码进行哈希处理的 C# 方法。

public static string ToHash(this string password, string salt)
{
if (string.IsNullOrEmpty(password))
return "";

var provider = new SHA1CryptoServiceProvider();
var encoding = new UnicodeEncoding();
var bytes = provider.ComputeHash(encoding.GetBytes(salt + password));
return Encoding.UTF8.GetString(bytes);
}

我试过在密码之前或之后加盐,目前根本不匹配,这里是来自 cakephp mysql 数据库的散列密码:

c7fb60ef77dbe3d1681a68e6741ee3a23cc1f41d

这是我的方法

��3[v"��1��:��ѐ��

不太确定在哪里/如何解决这个问题。任何帮助或提示将不胜感激。

谢谢

最佳答案

我有!

至少它适用于我的配置:

Core.php 中查找盐(在文件中搜索 Security.salt)。然后,使用此代码(与问题非常相似):

string input = textBox1.Text;
input = "your salt should be here" + input;
var provider = new SHA1CryptoServiceProvider();
var encoding = new UTF8Encoding();
var bytes = provider.ComputeHash(encoding.GetBytes(input));
sha1result.Text = Bin2Hex(bytes);

Bin2Hex 的助手也在这里:

public static string Bin2Hex(byte[] ba)
{
string hex = BitConverter.ToString(ba);
return hex.Replace("-", "");
}

找到它并不容易,我在网上搜索了一些(没有结果!),最后求助于资源挖掘。

关于c# - 从 C# 到 MySQL CakePhp 用户的身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13633806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com