locked
How to login using other filed (no duplicate) added to AspNetUsers table? RRS feed

  • Question

  • User-1846805900 posted

    Hi

    i have add some filed to my AspNetUsers table  like (ManagerID, RepID .... ect ), now i need to login user by RepID (int) i try to edit Login Code as:

            [HttpPost]
            [AllowAnonymous]
            [ValidateAntiForgeryToken]
            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.RepID, 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);
                }
            }

    but always result  return me err and don't out any thing just "Invalid login attempt." , when i use t with email it works :

     var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);

    so please how can i make it works with RepID or any other filed i need ?

    Friday, September 4, 2015 5:16 PM

All replies

  • User-271186128 posted

    Hi Eng.Ahmed

    According to your code and description, I suppose the issue is related to the PasswordSignInAsync method. Please check it.

    Here are some relevant articles, please refer to them:

    http://stackoverflow.com/questions/27054766/asp-net-identity-custom-signinmanager

    http://blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates.aspx

    http://forums.asp.net/t/1995795.aspx?ASP+NET+Identity+Username+Email

    Best regards,
    Dillion

    Sunday, September 6, 2015 11:34 PM
  • User-1846805900 posted

    as i understand i must add my own method to complete this task, so can you please give me sample code to know how can i do it ?

    Tuesday, September 8, 2015 8:13 PM
  • User-1846805900 posted

    any update please ?

    Wednesday, September 9, 2015 10:34 AM
  • User-698989805 posted

    If I am not wrong, you want to retrieve repID when you login with username or any other column. If that is the case, you should use something like:

     string username = txtName.Text;
    
               using(var context = new DemoEntities)
               {
                   var con = (from c in context.TableName
                              where c.ColumnName == username
                              select c.RepID).ToList();
               }

    Simply pass the username or any other column name (You may also use the email column - That would be better as it is always unique), then matching the column name you can get the repID.

    Wednesday, September 9, 2015 10:50 AM
  • User-1846805900 posted

    Thanks a lot,

    no i need to login with RepID not (username, Email) - so please how can i do that ?

    Wednesday, September 9, 2015 7:54 PM
  • User-698989805 posted

    Simply pass the repID in the TextBox:

    int repID = Convert.ToInt32(txtRepID.Text);
    
               using(var context = new DemoEntities)
               {
                   var con = (from c in context.TableName
                              where c.repID == repID
                              select c).ToList();
               }

    Thursday, September 10, 2015 3:42 AM
  • User-1846805900 posted
    Do you mean pass repid and find email or user name of it to login by email or user name ?
    I use aspnetuser table
    Thursday, September 10, 2015 8:01 AM
  • User-698989805 posted
    @a.amin I am not sure in which table you are using repID. I think it is in a different table. If you want to use it in aspnetuser table then you have to create another column in the aspnetuser or in aspnetuser table there is already an auto-incremented id and you can use it as repID.
    Thursday, September 10, 2015 8:14 AM