【发布时间】:2015-05-25 13:43:17
【问题描述】:
我有一个 C# 应用程序和一个 SQLite 数据库。在数据库中,我有一个包含几列的表。在其中一列中,我有一个使用查询中的 SHA1 加密的值。但我需要像这样在我的 C# 应用程序中使用它:
cmd.CommandText = "Select * from accounts where (username=@username and password=sha1(@password));";
我需要选择字符串值,以记录到应用程序。我收到错误:no such function sha1。
从其他帖子,如:This one,我知道我必须创建另一个函数来使用 sha1 进行散列?但我真的不明白如何做到这一点..有人可以帮助我吗?对不起,如果它是重复的,但我没有找到指定的答案。
【问题讨论】:
-
使用
Select * from accounts where (username=@username and password=@password);并绑定@password的哈希值 -
在大多数情况下,使用像
SHA1这样的哈希函数存储密码被认为是不安全的,请了解key derivation function,它被认为对密码存储更安全。 -
你的意思是这样的:
cmd.Parameters.AddWithValue("sha1(@password)", password);或cmd.Parameters.AddWithValue(sha1("@password"), password);?? -
感谢 dvhh 的建议!
-
在查询中使用
Select * from accounts where (username=@username and password=@password);作为查询,而在查询中没有sha1和cmd.Parameters.AddWithValue(@password",sha1(password)");,这意味着您必须在c# 代码中应用sha1,而不是在SQL 中。
标签: c# sqlite encryption hash sha1