SQL 查询创建加密密码
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑对您当前存储的密码进行哈希处理。 SQL 可以按如下方式对密码进行哈希处理:
...但是 SQL 甚至不需要这样做。您应该在 C# 应用程序收到密码后立即对密码进行哈希处理,然后仅将经过哈希处理的密码传递到 SQL 中进行保存。检查用户是否提供了正确的登录密码时,请比较哈希值。
Consider hashing the password that you currently store. SQL can hash a password as follows:
... 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.
最好的选择是单向加密。
在这种情况下发生的情况是用户选择/被给予密码。当该密码存储在数据库中时,它会在存储之前通过这种单向加密。 (您将在 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.