1

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; }
}
4
  • 1
    At first look, UniceNumber is an int, but PasswordSignInAsync is expecting a string Commented Oct 1, 2018 at 17:57
  • @GonzaloLorieto Yes, but can I change if want to use a Int value instead of Email or UserName for Login? Commented Oct 2, 2018 at 8:10
  • you can, but you must call UniqueNumber.ToString(). Is it working now? Commented Oct 2, 2018 at 13:20
  • Thanks Sir @GonzaloLorieto problem solved. :) Commented Oct 3, 2018 at 7:37

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Is their any way to use int value instead of string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.