How to change user login credentials in identity asp.net mvc?

Huzaifa

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; }
}
Mihail Stancescu

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.

edited at
0

Comments

0 comments
Login to comment

Related

ASP.NET MVC5 Identity issue with User.Identity.GetUserId() during login process

ASP.Net MVC Alternative Login to identity

How to unauthenticate current user ASP.net mvc Identity

Invalid Login Attempt with correct credentials ASP.NET Identity

How To Change Password Validation in ASP.Net MVC Identity 2?

Where is the appropriate spot to seed and login a default user with ASP.NET MVC Identity 2.0?

ASP.NET MVC 5 Identity 2 Login redirect based on user role

Add a Custom property to ASP.NET MVC Identity after user login

How to save user last login date if he was logged in with external login provider using ASP .Net Identity?

Can I change asp.net mvc 5 identity user ID from string(GUID) to int

How to add more user data to ASP.NET MVC user.Identity

How to load partial login and registration views with AngularJS and MVC5 (ASP.NET Identity)

How do I get the user details straight after login using Identity on ASP.NET Core?

How to disable account if user login fails continuously in Asp.Net Core identity

ASP.NET MVC Identity login without password

ASP.NET Core MVC Identity login issue

Login popup with Identity framework in ASP.NET MVC 5

ASP.NET Identity - Maintain login after updating user record

ASP.NET Identity user null after login

Overlap User Login in Two Projects with ASP.NET Identity

Change identity login URL in ASP.net core 3.0

Token based login logic change in ASP.NET Identity 2.0

How to edit a user in ASP.NET Identity

How do I change the ASP.NET MVC default login page to login by username instead of email address?

How to create new user accounts from another (admin role) account in ASP.NET MVC 5 (Identity)

How can keep the user logged in even after the browser has closed with Identity ASP.NET MVC framework?

How User.Identity.GetUserId() work in ASP.NET MVC5

How to get Identity User Data from Asp.net mvc Model

How does Identity work in project template with Individual user account for ASP.NET Core MVC 3.1?