我在Xamarin.Forms Portable应用程序中创建了一个Login Form。我有一个WebFormsProject,其中我创建了一个API控制器,用于比较用户输入的用户名和密码以及保存在我的数据库中的用户名和密码。ASP.NET中使用的散列方法Identity
保存在我的数据库上的密码是使用ASP.NET身份的哈希。虽然将由用户键入的密码使用Crypto.HashPassword进行散列(不知道这个类是否是ASP.NET身份的东西)。
我来测试输入自己的用户名和密码,使用这样的:
[路线( “API /登录/搜索/ {名}/{密码}”)
当我使用断点试试这将是我的密码钥匙,我得到这个散列值:
AL6kLGQYs3xeCtNkpJuAem43HOEvSpwzSfy5zCK0MviBGuS67Sp + ct0lNfJTd602Uw ==
虽然我的数据库中的密码有这个散列值:
AMlco7zkLpj5alL2MP1VEXQlRbcD2sdTdKB3JvTLzYMMwSUC5vSfhI4MloLLw70Erg ==
我不知道他们为什么即使我已经进入了相同的密码不同的哈希值。
如果两个密码匹配,它应该返回'true',否则返回false。我现在处于一个令人困惑的阶段。希望您能够帮助我。我想知道ASP.NET Identity使用什么哈希方法?谢谢。
这是我的一些代码。
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using WebFormsDemo;
using WebFormsDemo.ViewModel;
using System.Security.Cryptography;
using System.Web.Helpers;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security;
using Microsoft.AspNet.Identity.EntityFramework;
namespace WebFormsDemo.Controllers
{
public class LoginController : ApiController
{
private EBMSEntities db = new EBMSEntities();
[Route("api/Login/Search/{username}/{password}")]
[ResponseType(typeof(List<AspNetUser>))]
public bool getUserPassword(string username, string password)
{
var hashedPassword = "";
hashedPassword = Crypto.HashPassword(password);
var user = (from u in db.AspNetUsers
where u.UserName.Equals(username)
&& u.PasswordHash.Equals(hashedPassword)
select u).ToList();
if (user.Count() != 0)
{
return true;
}
return false;
}
}
}
通常密码是咸鱼所以每次生成一个散列时它会有所不同,即使是相同的密码。这就是为什么你需要知道盐来检查它们。它保存在结果本身中。无法确定这些内置系统的工作原理,但这很可能是原因。 –
@SamiKuhmonen你在谈论ASP.NET身份?它使用salt方法哈希密码? –
可能重复[ASP.NET身份散列密码与Crypto.HashPassword相比](http://stackoverflow.com/questions/39289540/asp-net-identity-hashed-password-compared-to-crypto-hashpassword) –