我正在使用下面的MVC5登录身份验证码:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
// Validate the password
IdentityResult result = IdentityManager.Authentication.CheckPasswordAndSignIn(AuthenticationManager, model.UserName, model.Password, model.RememberMe);
if (result.Success)
{
return Redirect("~/home");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
如果密码不正确,代码会给出一条消息,但如果用户名不存在,则会显示相同的消息,说明"密码不正确。"
有没有人有一个解决方案,也检查现有用户名,并提供正确的消息,如果它不存在?请注意,我正在使用ASP.Net Identity,因此它需要是一个解决方案,而不是简单成员身份验证
答案 0 :(得分:3)
如果更新到1.0 RTM标识包,则可以通过以下方式检查用户是否存在:
UserManager.FindByName("username")