哪个是使用MVC 4中的SimpleMembershipProvider访问webpages_Membership表信息的最佳方法?如果他/她输入错误密码三次,我正在尝试实施帐户阻止. 非常感谢 使用SimpleMembership,您将使用以下方法访问此
非常感谢
使用SimpleMembership,您将使用以下方法访问此信息:WebSecurity.IsAccountLockedOut(userName, allowedPasswordAttempts, intervalInSeconds)
IsAccountLockedOut根据您要允许的尝试次数以及自上次尝试登录失败以来的时间,返回帐户是否被锁定.这用于阻止暴力破解其他机器破解密码的企图.您可以在对用户进行身份验证的位置添加此检查,例如Account controllers Login方法.你可以这样做:
[HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid && !WebSecurity.IsAccountLockedOut(model.UserName, 3, 180) && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { return RedirectToLocal(returnUrl); } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); return View(model); }
在这种情况下,您不希望完全禁用用户,并允许有效用户在间隔过去后重新进入.这可以阻止暴力攻击而不是忘记密码的人.
在注册期间使用IsConfirmed字段,您希望用户确认他们为您提供了有效的电子邮件地址.您将在数据库中生成并存储ConfirmationToken,您将通过该电子邮件发送给用户,并指示他们单击链接,将其带到MVC应用程序中的控制器/操作,该控制器/操作将验证令牌并将IsConfirmed字段设置为true .