没有ASP.NET的FormsAuthentication,在C#Windows应用程序中进行密码散列?

8 .net c# passwords hash

我的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
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*ade 22

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);
}  
Run Code Online (Sandbox Code Playgroud)


Vai*_*hav 1

我认为应该有效。您需要做的就是在代码中引用 System.Web.Security(并将其添加为 Visual Studio 项目中的引用)。