如何保存在C#.NET中的密码? [英] How to save the Password in C# .NET?
问题描述
我想提出一个C#.NET应用程序,其中我已经设计了一个管理员帐户。我们在该帐户管理员必须输入密码登录。
我的问题是:我如何保存密码
可能的选项:
-
全局变量(显然不正确,因为这将被重置为默认值,每次我运行的应用程序)
-
数据库关系(可行的,但是它的作用是为标量关系只....)
我不希望将其存储在一个标量的关系,因为我认为这是愚蠢的使用关系只有一个入口和一个列!
有什么存储密码等方式最佳?
您可以存储它腌制,并在用户设置文件哈希。
私人布尔CheckPassword(字符串盐,字符串密码)$ b:您可以使用类似访问默认的设置文件$ b {
无功散= Encoding.ASCII.GetBytes(盐+密码);
变种SHA1 =新SHA1CryptoServiceProvider();
VAR sha1hash = sha1.ComputeHash(散);
VAR hashedPassword = ASCIIEncoding.GetString(sha1hash);
回报率(Properties.Settings.Default.adminPass == hashedPassword);
}
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 Question is : How do I save that password?
Possible options :
Global variable (Obviously incorrect because it will be reset to its default value everytime I run the application)
Database Relation (Feasible but it serves to be a scalar relation only....)
I don't want to store it in a scalar relation because I think it is stupid to use a relation for only one entry and one column!
Is there any other optimum way to store the password?
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);
}
这篇关于如何保存在C#.NET中的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!