自定义c++ ASP . net会员登录
Custom C++ ASP .NET Membership Login
有人知道如何使用ASP .NET会员提供的盐密钥来散列用户的密码吗?
我正在开发一个c++ Linux应用程序,我只能访问SQL Server。
谢谢,
下面是ASP使用的编码算法。Net会员,用c#编写。
它使用System.Security
,所以如果你想在linux上运行,你可能想看看MONO。
注:我不熟悉MONO。
private string EncodePassword(string pass, int passwordFormat, string salt)
{
if (passwordFormat == 0) // MembershipPasswordFormat.Clear
return pass;
byte[] bIn = Encoding.Unicode.GetBytes(pass);
byte[] bSalt = Convert.FromBase64String(salt);
byte[] bRet = null;
if (passwordFormat == 1)
{ // MembershipPasswordFormat.Hashed
HashAlgorithm hm = GetHashAlgorithm();
if (hm is KeyedHashAlgorithm)
{
KeyedHashAlgorithm kha = (KeyedHashAlgorithm)hm;
if (kha.Key.Length == bSalt.Length)
{
kha.Key = bSalt;
}
else if (kha.Key.Length < bSalt.Length)
{
byte[] bKey = new byte[kha.Key.Length];
Buffer.BlockCopy(bSalt, 0, bKey, 0, bKey.Length);
kha.Key = bKey;
}
else
{
byte[] bKey = new byte[kha.Key.Length];
for (int iter = 0; iter < bKey.Length; )
{
int len = Math.Min(bSalt.Length, bKey.Length - iter);
Buffer.BlockCopy(bSalt, 0, bKey, iter, len);
iter += len;
}
kha.Key = bKey;
}
bRet = kha.ComputeHash(bIn);
}
else
{
byte[] bAll = new byte[bSalt.Length + bIn.Length];
Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length);
Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length);
bRet = hm.ComputeHash(bAll);
}
}
else
{
byte[] bAll = new byte[bSalt.Length + bIn.Length];
Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length);
Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length);
bRet = EncryptPassword(bAll, _LegacyPasswordCompatibilityMode);
}
return Convert.ToBase64String(bRet);
}
private string GenerateSalt()
{
byte[] buf = new byte[SALT_SIZE];
(new RNGCryptoServiceProvider()).GetBytes(buf);
return Convert.ToBase64String(buf);
}
相关文章:
- 密码登录程序将永远循环并显示不正确的结果
- 在 C++/CLI 中将 .NET 事件从一个 DLL 引发到另一个 DLL
- 如何在 64 位 vb.net Windows 应用程序中引用 32 位 dll
- 如何检查cURL是否成功登录?c ++
- 加载与引用 .NET DLL 位于同一文件夹中的引用的 .NET DLL 时"Not found"异常
- 是否可以在Linux上使用.Net Core 3.1创建C++/CLI代码的C#DLL
- Poco::Net::FTPClientSession 在 open() 方法上挂起 129 秒,如果 ftp 主机不存
- C++ DLL(不是 CLI)是否可以调用 .NET Core 3.0 委托?
- System.AccessViolationException:shared_ptr C# .NET 和 C++ 应用程
- C++/CLI targetting .NET Core 3.1
- 是否有可能构建面向Linux和Windows的.Net Core C++ / CLI应用程序?
- 在 Tizen 中登录特定文件?
- WM_PAINT消息频率:C#(.Net Framework 4.7.2 WinForms)与C++
- 如何将 VB.Net 字符串作为字符*传递给C++dll?
- 从C++标头中导入常量而不是硬编码它们:扩展 .net 控件?
- 如何在 c++ 中将密码和用户名保存到 .txt 文件中.如果用户尝试登录,我仍然希望能够检索它们
- Win7 C++ - 从以用户身份登录的服务启动可执行文件的问题
- 在主窗口之前显示登录对话框并隐藏主窗口按钮
- VB.NET DLL中的C++DLL函数复制
- 自定义c++ ASP . net会员登录