How to save the Password in C# .NET?

后端 未结 5 1037
南笙
南笙 2021-01-13 12:50

I am making a C#.NET application wherein I have designed an Administrator account. Now to Login in that account the Administrator has to enter the password.

My Ques

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-13 13:23

    You can store it salted and hashed in a user settings file.

    You can access the default settings file using something like:

    private bool CheckPassword(string salt, string password) 
    {
       var hash = Encoding.ASCII.GetBytes(salt + password);
       var sha1 = new SHA1CryptoServiceProvider();
       var sha1hash = sha1.ComputeHash(hash);
       var hashedPassword = ASCIIEncoding.GetString(sha1hash);
    
       return (Properties.Settings.Default.adminPass == hashedPassword);
    }
    

提交回复
热议问题