如何使用 c# 对密码值进行加盐和哈希处理? [英] How to salt and hash a password value using c#?

查看:34
本文介绍了如何使用 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:

注册时:

  1. 使用您指定的算法散列用户密码并将其存储在数据库中
  2. Salt 这个哈希(可选,但首选)
  1. Hash a user's password using your specified algorithm and store it in the database
  2. Salt this hash (optional, but preferred)

登录/用户 &密码检查:

  1. 在数据库中查找用户名
  2. 如果存在,则检索散列密码
  3. 对输入的密码进行哈希和加盐,并将其与检索到的密码进行比较

都是比较啰嗦的,但是很安全.

It's all relatively long-winded, but it's very secure.

关于散列加盐这里还有另一个非常深入的指南.

这篇关于如何使用 c# 对密码值进行加盐和哈希处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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