Exemple #1
0
        public void ValidatePassword_ValidPassword_True()
        {
            Password = Generator.Generate(TestUserId);
            var validatedPassword = Validator.ValidatePassword(TestUserId, Password);

            Assert.IsTrue(validatedPassword);
        }
Exemple #2
0
        public IActionResult Index(LoginViewModel vm)
        {
            // Check if they entered a valid username / password combination
            var valid = PassValidator.ValidatePassword(_context, vm.UserName, vm.Password);

            // If not valid
            if (!valid)
            {
                // Set password back to null
                vm.Password = "";
                // Return back to the login page
                return(RedirectToAction("Index"));
            }

            // Set session username
            HttpContext.Session.SetString("Username", vm.UserName);
            var roleId = _context.Users.First(u => u.UserName == vm.UserName).RoleId;

            // Set session role
            HttpContext.Session.SetString("Role", _context.Roles.First(r => r.RoleId == roleId).RoleName);


            // Redirect to the dashboard - SUCCESSFUL LOGIN
            return(Redirect("Project/Dashboard"));
        }