SQL 查询创建加密密码

发布于 2024-11-06 15:20:52 字数 118 浏览 0 评论 0原文

我正在尝试在 c# 中创建一个安全密码登录屏幕。现在我刚刚创建了登录屏幕,我可以从数据库中读取用户名和密码。但是我设计的密码没有加密。任何人都可以帮助我如何编写查询来生成加密密码并将加密密码值存储在单独的字段中。提前致谢。

I am trying to create a secure password login screen in c#.Right now i have just created the login screen and I am able to read the username and password from the database.But which i have designed does not have an encrypted password. Can any one help me out how to write a query to generate encrypted password and store the encrypted password value in a separate field.Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只为守护你 2024-11-13 15:20:52

考虑对您当前存储的密码进行哈希处理。 SQL 可以按如下方式对密码进行哈希处理:

DECLARE @HashThisPassword nvarchar(4000);
SELECT @HashThisPassword = CONVERT(nvarchar(4000),'dslfdkjLK85kldhnv$n000#knf');
SELECT HashBytes('SHA1', @HashThisPassword);

...但是 SQL 甚至不需要这样做。您应该在 C# 应用程序收到密码后立即对密码进行哈希处理,然后仅将经过哈希处理的密码传递到 SQL 中进行保存。检查用户是否提供了正确的登录密码时,请比较哈希值。

Consider hashing the password that you currently store. SQL can hash a password as follows:

DECLARE @HashThisPassword nvarchar(4000);
SELECT @HashThisPassword = CONVERT(nvarchar(4000),'dslfdkjLK85kldhnv$n000#knf');
SELECT HashBytes('SHA1', @HashThisPassword);

... But SQL shouldn't even need to do this. You should hash the password as soon as your C# application receives it, and then only ever pass the hashed password into SQL to be saved. When checking if the user has provided the correct password for login, compare the hashes.

童话 2024-11-13 15:20:52

最好的选择是单向加密。

在这种情况下发生的情况是用户选择/被给予密码。当该密码存储在数据库中时,它会在存储之前通过这种单向加密。 (您将在 C# 代码中执行此操作)

然后,当用户登录时,输入的密码会先经过相同的单向加密,然后再与数据库中的密码进行比较。

这确保了如果黑客进入数据库,就很难获悉密码,因为他们必须确定加密类型,然后设计一种方法来解密它,据我所知,这充其量是困难的,甚至是不可能的。最糟糕的。

这是一些可能有帮助的代码的链接。 单向加密

您不想进行加密在 sql 本身中,因为如果黑客确实访问了您的数据库,他们将能够简单地查看您用来进行加密的过程/函数,并且他们将轻松得多。

而且您也不希望将密码以未加密的方式存储在数据库中...

您最好的选择是编写一些代码来读取密码,对其进行加密并更新记录,然后您所要做的就是继续使用相同的加密类型和盐。

C# 密码学库非常易于使用。

Your best bet is one way encryption.

What happens in this scenario is the user selects/is given a password. When that password is stored in the database it passes thorugh this one way encryption before it is stored. (You'll be doing this in your c# code)

Then when the user logs in, the entered password passes through this same one way encryption before it is compared with the password in the database.

This ensures that if a hacker gets into the database, it will be difficult to learn the password because they would have to determine the encryption type, and then devise a way to un-encrypt it which to my understanding is difficult at best, impossible at worst.

Here is a link to some code that may help. One Way Encryption

You don't want to do the encryption in sql itself, because if a hacker DOES access your database, they will be able to simply look at the procedure/function that you are using to do the encryption and they will have a much easier time.

And you don't want to store the password in the database unencrypted as well...

Your best bet is to write some code to read the password, encrypt it, and update the record, then all you have to do is continue to use the same encryption type and salt.

The c# cryptography library is very easy to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文