From 68adc68f78eeefbe2b586b732a956d0aaffab7bf Mon Sep 17 00:00:00 2001 From: Dimitar Todorov <36155679+thermalthrottle@users.noreply.github.com> Date: Tue, 5 Apr 2022 23:29:10 +0300 Subject: [PATCH] Fixed crash on login Fixed crash where if the user tries to login with a wrong or non-existent username it crashes the app --- RentACar/WebApp/Areas/Identity/Pages/Account/Login.cshtml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RentACar/WebApp/Areas/Identity/Pages/Account/Login.cshtml.cs b/RentACar/WebApp/Areas/Identity/Pages/Account/Login.cshtml.cs index f0d900b..9a96226 100644 --- a/RentACar/WebApp/Areas/Identity/Pages/Account/Login.cshtml.cs +++ b/RentACar/WebApp/Areas/Identity/Pages/Account/Login.cshtml.cs @@ -86,7 +86,7 @@ namespace WebApp.Areas.Identity.Pages.Account { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true - var result = await _signInManager.PasswordSignInAsync(rentACarDbContext.Users.FirstOrDefault(user => user.UserName == Input.Username), Input.Password, Input.RememberMe, lockoutOnFailure: false); + var result = await _signInManager.PasswordSignInAsync(rentACarDbContext.Users.FirstOrDefault(user => user.UserName == Input.Username) ?? new User(), Input.Password, Input.RememberMe, lockoutOnFailure: false); if (result.Succeeded) { _logger.LogInformation("User logged in.");