[Sql-Server]用于密码salt和hash值的数据类型以及长度是多少? [英] [Sql-Server]what data type to use for password salt and hash values and what length?

查看:418
本文介绍了[Sql-Server]用于密码salt和hash值的数据类型以及长度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过使用密码从密码生成salt和hash值。

  string salt = CreateSalt(TxtPassword.Text.Length ); 
string hash = CreatePasswordHash(TxtPassword.Text,salt);

私有静态字符串CreateSalt(int size)
{
//生成一个加密随机数。
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
byte [] buff = new byte [size];
rng.GetBytes(buff);

//返回随机数的Base64字符串表示。
return Convert.ToBase64String(buff);


private static string CreatePasswordHash(string pwd,string salt)
{
string saltAndPwd = String.Concat(pwd,salt);
字符串hashedPwd =
FormsAuthentication.HashPasswordForStoringInConfigFile(
saltAndPwd,sha1);

返回hashedPwd;





$ b

在sql server中存储这些值的建议是什么数据类型?任何建议......



盐: 9GsPWpFD



Hash: E778AF0DC5F2953A00B35B35D80F6262CDBB8567

解决方案

ASPNET_DB说 - 不能去

 密码nvarchar(128)NOT NULL,
PasswordSalt nvarchar(128)NOT NULL,

虽然128可能看起来很多,但各种类型的加密可能导致比您开始使用的字符串更大的字符串。绝对没有理由不跟随那些花费数千人开发asp.net会员系统的聪明人的领导。


I am generating salt and hash values from my passwords by using,

string salt = CreateSalt(TxtPassword.Text.Length);
string hash = CreatePasswordHash(TxtPassword.Text, salt);

private static string CreateSalt(int size)
{
    //Generate a cryptographic random number.
    RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
    byte[] buff = new byte[size];
    rng.GetBytes(buff);

    // Return a Base64 string representation of the random number.
    return Convert.ToBase64String(buff);
}

private static string CreatePasswordHash(string pwd, string salt)
{
    string saltAndPwd = String.Concat(pwd, salt);
    string hashedPwd =
     FormsAuthentication.HashPasswordForStoringInConfigFile(
     saltAndPwd, "sha1");

    return hashedPwd;
}

What datatype you would suggest for storing these values in sql server? Any suggestion...

Salt:9GsPWpFD

Hash:E778AF0DC5F2953A00B35B35D80F6262CDBB8567

解决方案

ASPNET_DB says this - can't go wrong.

Password nvarchar(128) NOT NULL,
PasswordSalt nvarchar(128) NOT NULL,

while 128 may seem like a lot, various types of encryption can result in larger strings than you started out with. There is absolutely no reason not to follow the lead of the very smart people who have spend thousands of man hours developing the asp.net membership system.

这篇关于[Sql-Server]用于密码salt和hash值的数据类型以及长度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆