在Asp.Net Identity 2中建立自定义用户检查密码 [英] Build a custom user check password in Asp.Net Identity 2

查看:99
本文介绍了在Asp.Net Identity 2中建立自定义用户检查密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在使用asp.net MVC 5实现并使用Asp.Net Identity 2的应用程序中构建自定义用户密码检查.

I need to build a custom user password check in an application implemented in asp.net MVC 5 and using Asp.Net Identity 2.

我读了一个stackoverflow帖子(编写自定义IUserPasswordStore和Identity 2.1中的SignInManager.PasswordSignInAsync ),我只需要覆盖UserManager中的CheckPasswordAsync方法即可.

I read in a stackoverflow post (Writing a custom IUserPasswordStore and SignInManager.PasswordSignInAsync in Identity 2.1) that I only need to override the CheckPasswordAsync method in UserManager.

我尝试在IdentityConfig.cs文件中覆盖此方法.这是我添加到ApplicationUserManager类中的代码,仅用于测试此解决方案:

I try to override this method in IdentityConfig.cs file. Here is the code that I add to the ApplicationUserManager class just for test this solution:

public override async Task<bool> CheckPasswordAsync(ApplicationUser user,   string password)
{
        return await Task.Run(() => {
            return true;
        });
}

问题在于此代码永远不会在登录过程中运行,并且登录始终会失败.要登录用户,我使用SignInManager.PasswordSignInAsync登录用户,这是在asp.net MVC 5中创建新的Web应用程序时的默认设置. CheckPasswordAsync?还是需要其他配置来完成这项工作?

The problem is that this code is never run in the login process, and the login always fail. To sign in the user I’m using the SignInManager.PasswordSignInAsync to log in the user, this is the default when creating a new web application in asp.net MVC 5. Shouldn’t this method call the ApplicationUserManager. CheckPasswordAsync? Or there is another configuration needed to this work?

推荐答案

问题是我试图使用系统中不存在的用户登录.

The problem was that I was trying to login with a user that do not exists in the system.

SignInManager.PasswordSignInAsync永远不会调用ApplicationUserManager.如果用户存储库中不存在该用户,请执行CheckPasswordAsync.

The SignInManager.PasswordSignInAsync never invoke the ApplicationUserManager. CheckPasswordAsync if the user not exists in the user store repository.

总而言之,我必须将用户存储在应用程序中或实现自定义用户存储机制.

In conclusion, I have to store the users in my application or implement a custom user store mechanism.

这篇关于在Asp.Net Identity 2中建立自定义用户检查密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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