public static string HashPassword(string password)
{
if (password == null)
{
throw new ArgumentNullException("password");
}
byte[] salt;
byte[] bytes;
using (Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, 16, 1000))
{
salt = rfc2898DeriveBytes.Salt;
bytes = rfc2898DeriveBytes.GetBytes(32);
}
byte[] array = new byte[49];
Buffer.BlockCopy(salt, 0, array, 1, 16);
Buffer.BlockCopy(bytes, 0, array, 17, 32);
return Convert.ToBase64String(array);
} public static bool VerifyHashedPassword(string hashedPassword, string password)
{
if (hashedPassword == null)
{
return false;
}
if (password == null)
{
throw new ArgumentNullException("password");
}
byte[] array = Convert.FromBase64String(hashedPassword);
if (array.Length != 49 || array[0] != 0)
{
return false;
}
byte[] array2 = new byte[16];
Buffer.BlockCopy(array, 1, array2, 0, 16);
byte[] array3 = new byte[32];
Buffer.BlockCopy(array, 17, array3, 0, 32);
byte[] bytes;
using (Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, array2, 1000))
{
bytes = rfc2898DeriveBytes.GetBytes(32);
}
return ByteArraysEqual(array3, bytes);
} private static bool ByteArraysEqual(byte[] a, byte[] b)
{
if (object.ReferenceEquals(a, b))
{
return true;
}
if (a == null || b == null || a.Length != b.Length)
{
return false;
}
bool flag = true;
for (int i = 0; i < a.Length; i++)
{
flag &= (a[i] == b[i]);
}
return flag;
}

  

ASP.NET.Identity 加密算法的更多相关文章

  1. 从Membership 到 .NET4.5 之 ASP.NET Identity

    我们前面已经讨论过了如何在一个网站中集成最基本的Membership功能,然后深入学习了Membership的架构设计.正所谓从实践从来,到实践从去,在我们把Membership的结构吃透之后,我们要 ...

  2. MVC5 - ASP.NET Identity登录原理 - Claims-based认证和OWIN

    在Membership系列的最后一篇引入了ASP.NET Identity,看到大家对它还是挺感兴趣的,于是来一篇详解登录原理的文章.本文会涉及到Claims-based(基于声明)的认证,我们会详细 ...

  3. ASP.NET Identity入门系列教程(一) 初识Identity

    摘要 通过本文你将了解ASP.NET身份验证机制,表单认证的基本流程,ASP.NET Membership的一些弊端以及ASP.NET Identity的主要优势. 目录 身份验证(Authentic ...

  4. [转]MVC5 - ASP.NET Identity登录原理 - Claims-based认证和OWIN

    本文转自:http://www.cnblogs.com/jesse2013/p/aspnet-identity-claims-based-authentication-and-owin.html 在M ...

  5. Configuring Autofac to work with the ASP.NET Identity Framework in MVC 5

    https://developingsoftware.com/configuring-autofac-to-work-with-the-aspnet-identity-framework-in-mvc ...

  6. asp.net identity UserSecurityStamp 的作用

    UserSecurityStamp 主要是用来对用户安全相关信息做一个快照. 在使用asp.net identity 的 CreateAsync(TUser user) 创建一个用户的时候,如果开启了 ...

  7. ASP.NET Identity V2

    Microsoft.AspNet.Identity是微软在MVC 5.0中新引入的一种membership框架,和之前ASP.NET传统的membership以及WebPage所带来的SimpleMe ...

  8. ASP.NET Identity 2新增双重认证、帐号锁定、防伪印章功能并修复了一些bug

    Microsoft最近发布了ASP.NET Identity 2,该版本支持双重认证.帐号锁定以及防伪印章功能,还增强了用户帐号和索引.此外新版本还包含一个改进的密码验证器并修复了一些bug. 借助于 ...

  9. VS2013中web项目中自动生成的ASP.NET Identity代码思考

    vs2013没有再分webform.mvc.api项目,使用vs2013创建一个web项目模板选MVC,身份验证选个人用户账户.项目会生成ASP.NET Identity的一些代码.这些代码主要在Ac ...

随机推荐

  1. qemu网络虚拟化之数据流向分析二

    2016-09-27 上篇文章大致介绍了qemu网络虚拟化相关的数据结构,本篇就结合qemu-kvm源代码分析下各个数据结构是如何初始化以及建立联系的. 这里还是分为三个部分: 1.Tap设备区 2. ...

  2. pycharm修改选中字体颜色

    File->Setting->Editor->Color Scheme->General Scheme:Monokai 在方框内: Editor->Section Bac ...

  3. vim 设置字体和解决乱码

    在 C:\Program Files (x86)\Vim 目录中的 _vimrc 文件中加入下面两行 set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bo ...

  4. OpenCV膨胀与腐蚀

    膨胀与腐蚀 本篇博客主要介绍使用OpenCV中的函数接口实现对一个图片的腐蚀或者膨胀,听起来有点像是对图像进行放大和缩小的意思,如果你也是这样认为,那我只能说你跟我一样肤浅!!在OpenCV中几乎所有 ...

  5. Web UI 自动化单个xpath抓取插件详解

    原文地址http://blog.csdn.net/kaka1121/article/details/51878346 单个控件获取 需求: 右键到某个控件上,就能获取到至多三个可以唯一定位该元素的相对 ...

  6. 003-spring boot项目的项目属性配置

    一.application.properties文件. 1.项目的配置文件内容.配置了端口,超时连接时间, 2.控制器. 3.访问. 二.application.yml文件 1.application ...

  7. jQuery—$让渡

    方法1:(取别名) 方法2:(指定作用域) 场景用例: 解决方案:方法1(取别名) 解决方案:方法2(指定作用域)

  8. Error: UserWarning: Ignoring URL... 已解决

    数据data里存有url,用pandas的to_excel() 报错:UserWarning: Ignoring URL... 解决方案: 将 data.to_excel("data.xls ...

  9. 131. Palindrome Partitioning(回文子串划分 深度优先)

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  10. 【android】开发笔记---存储篇

    SQLite批量插入数据 当我们执行 db.execSQL("sql语句")的时候,系统进行了一次IO操作,当批量插入成千上万条时,就会消耗掉许多资源. 解决之道是通过事务,统一提 ...