【发布时间】:2013-11-12 22:04:30
【问题描述】:
尝试将默认最小密码长度更改为 4 个字符。我知道,4!!!可笑,对吧!不是我的电话。
无论如何,我已经在RegisterViewModel 上更改了它,但这实际上并没有改变它。为了说明我已经发布了下面的代码。 ModleState.IsValid 根据更新的 ViewModel 正确返回。但是,它随后会调用 UserManager.CreateAsync() 并返回 False 并带有“密码必须至少为 6 个字符”的错误消息
我已经按照这个非常相似的帖子 (Change Password...) 中的步骤进行操作,但据我所知,它不适用于 MVC 5。它仍然返回相同的消息。
//
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser() { UserName = model.UserName, LastLogin = model.LastLogin };
// This is where it 'fails' on the CreateAsync() call
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
【问题讨论】:
标签: .net simplemembership asp.net-mvc-5 asp.net-identity