How to salt and hash a password value using c#?(如何使用 c# 对密码值进行加盐和哈希处理?)
问题描述
大家好,
我从 在数据库中存储密码的首选方法...
如何使用 c# 对密码值加盐和散列?
How to salt and hash a password value using c#?
如何比较数据库中存储的值和用户给出的值?
How to compare both the values stored in DB and the one given by the user?
推荐答案
最流行的方法是使用散列算法.这里有一篇很棒的博文 关于如何使用 MD5 算法对字符串进行哈希处理,但在 System.Cryptography 命名空间中还有许多其他示例.
The most popular way to do this is using a hashing algorithm. There's an excellent blog post here about how to use the MD5 algorithm to hash a string, but there are many other examples in the System.Cryptography namespace.
至于 #2,关于其工作原理的一般分步指南如下:
As for #2, the general step-by-step guide to how this would work would be the following:
注册时:
- 使用您指定的算法散列用户密码并将其存储在数据库中
- Salt 这个哈希(可选,但首选)
- Hash a user's password using your specified algorithm and store it in the database
- Salt this hash (optional, but preferred)
登录/用户 &密码检查:
- 在数据库中查找用户名
- 如果存在,则检索散列密码
- 对输入的密码进行哈希和加盐,并将其与检索到的密码进行比较
都是比较啰嗦的,但是很安全.
It's all relatively long-winded, but it's very secure.
关于散列和加盐这里还有另一个非常深入的指南.
这篇关于如何使用 c# 对密码值进行加盐和哈希处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 c# 对密码值进行加盐和哈希处理?
基础教程推荐
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 如果条件可以为空 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 将数据集转换为列表 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
