c# - C# Windows 应用程序中的密码散列,缺少 ASP.NET 的 FormsAuthentication?

标签 c# .net hash passwords

我的 Win 表单应用程序似乎不喜欢 FormsAuthentication,我对散列完全陌生,因此非常欢迎任何转换它的帮助。谢谢。

//Write hash
protected TextBox tbPassword;
protected Literal liHashedPassword;

{
  string strHashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(tbPassword.Text, "sha1");
  liHashedPassword.Text = "Hashed Password is: " + strHashedPassword;    
}

//read hash
string strUserInputtedHashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile( tbPassword.Text, "sha1");
if(strUserInputtedHashedPassword == GetUsersHashedPasswordUsingUserName(tbUserName.Text))
{
  // sign-in successful
}
else
{
  // sign-in failed
}

最佳答案

using System.Security.Cryptography;

public static string EncodePasswordToBase64(string password)
{  byte[] bytes   = Encoding.Unicode.GetBytes(password);
   byte[] inArray = HashAlgorithm.Create("SHA1").ComputeHash(bytes);
   return Convert.ToBase64String(inArray);
}  

关于c# - C# Windows 应用程序中的密码散列,缺少 ASP.NET 的 FormsAuthentication?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/212763/

相关文章:

c# - TNS :could not resolve the connect identifier specified I have done the research

c# - 手动测试应用程序

c# - 使用 LINQ 过滤两个日期之间的数据

hash - 多对一映射哈希函数

hash - 密码盐如何帮助抵御彩虹表攻击?

c# 多个 web.config 文件在不同文件夹下的单个项目中?

C# - MVVM 中的第二个选项卡项中不显示弹出窗口

c# - 子项目引用的某些 DLL 未复制到解决方案的输出文件夹

c# - 使用正则表达式忽略带有数字的字符串中的日期

ruby-on-rails - rspec 分配将哈希键转换为字符串