使用BCrypt通过c#在MS Sql数据库表中哈希密码 [英] Using BCrypt to hash password in a MS Sql database table via c#

查看:80
本文介绍了使用BCrypt通过c#在MS Sql数据库表中哈希密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用BCrypt哈希登录密码后,我无法登录数据库。下面是我的代码片段。



private void button_Click(对象发送者,EventArgs e)



{$ / $




SqlConnection conn = new SqlConnection(........................................);















string userID = Microsoft.VisualBasic.Interaction.InputBox(请输入用户ID,用户ID); //提示用户输入用户ID



string pwd = Microsoft.VisualBasic.Interaction.InputBox(请输入密码,密码);



//用户输入密码



string salt = BCryptHelper.GenerateSalt(8);



string hashPwd = BCryptHelper.HashPassword(pwd,salt);



bool checkPwd = BCryptHelper.CheckPassword(pwd,hashPwd );







conn.Open();



SqlCommand sqlCmd = new SqlCommand(UPDATE Table_Person SET Password = @Password WHERE User ID = @UserID,conn);



sqlCmd.Parameters .AddWithValue(@ Password,hashPwd);



sqlCmd.Parameters.AddWithValue(@ UserID,userID);



sqlCmd.Ex ecuteNonQuery();





conn.Close();



}



我在这里做错了什么?我的数据库表中的密码字段已经过哈希处理,但我该如何解密呢?有人可以帮帮忙吗。

解决方案

正如我昨天提到这个问题所说:如何使用BCrypt在SQL表上存储密码 [ ^ ]



不加密密码。哈希:密码存储:如何操作。 [ ^ ]

I'm having trouble logging in my database after I used BCrypt to hash login password. Below is a snippet of my code.

private void button_Click(object sender, EventArgs e)

{


SqlConnection conn = new SqlConnection(………………………………….);







string userID =Microsoft.VisualBasic.Interaction.InputBox ("Please enter User ID", "User ID"); // prompt user to enter user ID

string pwd = Microsoft.VisualBasic.Interaction.InputBox ("Please enter password", "PASSWORD");

// promt user to enter a password

string salt = BCryptHelper.GenerateSalt(8);

string hashPwd = BCryptHelper.HashPassword (pwd, salt);

bool checkPwd = BCryptHelper.CheckPassword (pwd, hashPwd);



conn.Open ();

SqlCommand sqlCmd = new SqlCommand ("UPDATE Table_Person SET Password = @Password WHERE User ID = @UserID", conn);

sqlCmd.Parameters.AddWithValue ("@Password", hashPwd);

sqlCmd.Parameters.AddWithValue ("@UserID", userID);

sqlCmd.ExecuteNonQuery ();


conn.Close ();

}

What I'm my doing wrong here? The password field from my database table has been hashed, but how do I decrypt it back? Can someone help please.

解决方案

As I said when you asked this question yesterday: How to store password on a SQL table using BCrypt[^]

Don't encrypt passwords. Hash them: Password Storage: How to do it.[^]


这篇关于使用BCrypt通过c#在MS Sql数据库表中哈希密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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