【发布时间】:2016-09-02 09:54:18
【问题描述】:
大家好。我目前正在 Xamarin.Forms 便携式应用程序中创建登录表单。我有一个 WebFormsProject,我在其中创建了一个 API 控制器,用于比较用户输入的用户名和密码与保存在我的数据库中的用户名和密码。
保存在我的数据库中的密码是使用 ASP.NET 身份进行哈希处理的。虽然用户输入的密码使用 Crypto.HashPassword 进行哈希处理(不知道这个类是否是 ASP.NET Identity 的东西)。
如何比较这两者?
如果两个密码匹配,它应该返回'true',否则返回false。我现在处于一个混乱的阶段。希望您能够帮助我。谢谢。
这是我的一些代码。
LoginController.cs
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();
// GET: api/Login
[Route("api/Login/Search/{username}/{password}")]
[ResponseType(typeof(List<AspNetUser>))]
public bool getUsernamePassword(string username, string password)
{
var hashedPassword = "";
hashedPassword = Crypto.HashPassword(password);
var pass = (from u in db.AspNetUsers
where u.UserName.Equals(username)
select u.PasswordHash).Take(1);
string hashpassinDb = Convert.ToString(pass.FirstOrDefault());
return Crypto.VerifyHashedPassword(hashpassinDb, hashedPassword);
}
}
}
【问题讨论】:
标签: c# asp.net xamarin xamarin.forms asp.net-identity