当前位置: 首页>>代码示例>>C#>>正文


C# UserManager.CheckPassword方法代码示例

本文整理汇总了C#中UserManager.CheckPassword方法的典型用法代码示例。如果您正苦于以下问题:C# UserManager.CheckPassword方法的具体用法?C# UserManager.CheckPassword怎么用?C# UserManager.CheckPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserManager的用法示例。


在下文中一共展示了UserManager.CheckPassword方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidLogin

        bool ValidLogin(Login login)
        {
            UserStore<IdentityUser> userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> userManager = new UserManager<IdentityUser>(userStore)
            {
                UserLockoutEnabledByDefault = true,
                DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0),
                MaxFailedAccessAttemptsBeforeLockout = 3
            };
            var user = userManager.FindByName(login.UserName);

            if (user == null)
                return false;

            // User is locked out.
            if (userManager.SupportsUserLockout && userManager.IsLockedOut(user.Id))
            {
                return false;
            }

            // Validated user was locked out but now can be reset.
            if (userManager.CheckPassword(user, login.Password))
            {
                if (userManager.SupportsUserLockout
                 && userManager.GetAccessFailedCount(user.Id) > 0)
                {
                    userManager.ResetAccessFailedCount(user.Id);
                }
            }

            // Login is invalid so increment failed attempts.
            else {
                bool lockoutEnabled = userManager.GetLockoutEnabled(user.Id);
                if (userManager.SupportsUserLockout && userManager.GetLockoutEnabled(user.Id))
                {
                    userManager.AccessFailed(user.Id);
                    return false;
                }
                CaptchaHelper captchaHelper = new CaptchaHelper();
                string captchaResponse = captchaHelper.CheckRecaptcha();
                if (captchaResponse != "Valid")
                {
                    ViewBag.ErrorResponse = "The captcha must be valid";

                }
            }
            return true;
        }
开发者ID:andrewstec,项目名称:phase2_lastday,代码行数:48,代码来源:HomeController.cs

示例2: ValidLogin

        bool ValidLogin(Login login)
        {
            UserStore<IdentityUser> userStore = new UserStore<IdentityUser>();
            UserManager<IdentityUser> userManager = new UserManager<IdentityUser>(userStore)
            {
                UserLockoutEnabledByDefault = true,
                DefaultAccountLockoutTimeSpan = new TimeSpan(0, 10, 0),
                MaxFailedAccessAttemptsBeforeLockout = 3
            };
            var user = userManager.FindByName(login.UserName);

            if (user == null)
                return false;

            // User is locked out. 
            if (userManager.SupportsUserLockout && userManager.IsLockedOut(user.Id))
                return false;

            // Validated user was locked out but now can be reset. 
            if (userManager.CheckPassword(user, login.Password)
                    && userManager.IsEmailConfirmed(user.Id))
            {
                if (userManager.SupportsUserLockout
                 && userManager.GetAccessFailedCount(user.Id) > 0)
                {
                    userManager.ResetAccessFailedCount(user.Id);
                }
            }
            // Login is invalid so increment failed attempts. 
            else {
                bool lockoutEnabled = userManager.GetLockoutEnabled(user.Id);
                if (userManager.SupportsUserLockout && userManager.GetLockoutEnabled(user.Id))
                {
                    userManager.AccessFailed(user.Id);
                    return false;
                }
            }
            return true;
        }
开发者ID:JayOwl,项目名称:Bruteforce-Attack-Prevention,代码行数:39,代码来源:HomeController.cs

示例3: AuthenticateCompany

 //checks the recieved username and password against the database to see if the identity is present and if the password mathces.
 public bool AuthenticateCompany(string userName, string password)
 {
     var ctx = new Context();
     var um = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(ctx));
     
     if (um.CheckPassword(um.FindByEmail(userName), password))
     {
         return true;
     }
     
     return false;
 }
开发者ID:Xorthos,项目名称:3.SemesterProject-Saatsea,代码行数:13,代码来源:CompanyRepository.cs


注:本文中的UserManager.CheckPassword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。