0

I have want to implement login in asp. net. I can register and AddPassword is true. My password has stored into my database. But when I want to login again it's failed. I got exception here when using CheckPasswordAsync. Here is My code for Register

var result = await UserManager.CreateAsync(user);
var isAddedPassword = await UserManager.AddPasswordAsync(user.Id, model.Password);

Here it is when I want to login

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
    {
        if (!ModelState.IsValid)
        {
            return View(model);
        }
        var foundUser = await UserManager.FindByEmailAsync(model.Email);
        if (foundUser == null)
        {
            ViewBag.Message = "NotRegistered";
            return View();
        }
        var user = await UserManager.FindAsync(foundUser.UserName, model.Password);
        var password = await _userManager.CheckPasswordAsync(foundUser, model.Password);
        var result = await SignInManager.PasswordSignInAsync(foundUser.UserName, model.Password, model.RememberMe, shouldLockout: false);

Any ideas SignInManager.PasswordSignInAsync return failure and CheckPassword got exception?

santro
  • 67
  • 1
  • 9
  • Are you absolutely sure that `CheckPasswordAsync` returns `null`? That's not possible as the return type is `bool` – DavidG Feb 11 '17 at 20:26
  • @DavidG I got this error on that line Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. – santro Feb 11 '17 at 20:30
  • There's a **huge** difference between "return null" and throwing an exception... – DavidG Feb 11 '17 at 20:31
  • @DavidG I'm sorry for my mistake, I'm just new at programming. Thanks for correcting me. But Do you have any idea why i got exception? – santro Feb 11 '17 at 20:33
  • I marked this question as a duplicate, that will help you diagnose a NullReferenceException – DavidG Feb 11 '17 at 20:51
  • it's sounds not good – santro Feb 11 '17 at 21:19

0 Answers0