public IActionResult Login(string UserName, string Pword) { int passFound = 0; int userFound = 0; var custLoginInfo = StoreMethods.GetCustomers(_db); foreach (var customer in custLoginInfo) //Check to make sure valid login info { if (UserName == customer.UserName) //entered user name corresponds to existing username for logged in user { userFound++; if (Pword == customer.Pword) //entered password corresponds to existing pass for logged in user { passFound++; _logger.LogInformation("User logged in"); _cache.Set("loggedInCustomer", customer); //Set the logged in customer to be the customer who just passed the login check return(View("_StoreMenu")); } } } if (userFound == 0) //Print out error messages according to what was entered incorrectly { _logger.LogInformation("Incorrect username"); ModelState.AddModelError("Username", "Incorrect username"); return(View("_Login")); } if (passFound == 0) { _logger.LogInformation("Correct user, incorrect pass"); ModelState.AddModelError("Pword", "Incorrect password"); return(View("_Login")); } return(View("_Login")); }
public void GetCustomerReturnsListOfCustomers() { var options = new DbContextOptionsBuilder <SGDB2Context>() .UseInMemoryDatabase(databaseName: "SGDB2") .Options; using (var context = new SGDB2Context(options)) { var result = StoreMethods.GetCustomers(context); Assert.IsType <List <Customers> >(result); } }//1