I'm new in MVC and working on User Authentication Authorization. I want to change user login credential with UniqueNumber instead of Email.
I tried but it throws this error
Error 1 : The best overloaded method match for 'Microsoft.AspNet.Identity.Owin.SignInManager.PasswordSignInAsync(string, string, bool, bool)' has some invalid arguments
Login Action
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, change to shouldLockout: true
var result = await SignInManager.PasswordSignInAsync(model.UniqueNumber, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
}
LoginViewModel
public class LoginViewModel
{
[Required]
[Display(Name = "Unique Number")]
public int UniqueNumber { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
Considering this question may be a duplicate of this SO answer:
You must change the registration of the users to use the UniqueNumber
instead of the email when calling: var user = new ApplicationUser { UserName = model.UniqueNumber, Email = model.Email };
.
And yes, as @Gonzalo Lorieto said you must cast the UniqueNumber
to string.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments