public IActionResult Login(LoginViewModel loginViewModel)
        {
            if (ModelState.IsValid)
            {
                List <User> matches1 = context.Members.Where(c => c.Username == loginViewModel.username).ToList();

                string passobj = "cheese" + loginViewModel.password;

                Hashobject newhash = new Hashobject(passobj);
                string     Hash    = newhash.Hashedstring(passobj);

                List <User> matches2 = matches1.Where(c => c.Password == Hash).ToList();

                if (matches2.Count == 1)
                {
                    User logusr = matches1.Single(c => c.Password == Hash);
                    currentuser = logusr;
                    Loggedin    = "true";
                    return(Redirect("/Home/LoggedIn"));
                }

                else
                {
                    ViewBag.error = "No such user found in database. Feel free to register.";
                    return(View());
                }
            }

            else
            {
                return(View());
            }
        }
        public IActionResult AddUser(AddUserViewModel addUserViewModel)
        {
            if (ModelState.IsValid)
            {
                if (addUserViewModel.verify == addUserViewModel.password)
                {
                    int pwlen = addUserViewModel.password.Length;

                    if (pwlen < 9)


                    {
                        ViewBag.error = "The password must be longer than 8 characters.";
                        return(View());
                    }

                    String pwtest = addUserViewModel.password;

                    var withoutSpecial = new string(pwtest.Where(c => Char.IsLetterOrDigit(c) ||
                                                                 Char.IsWhiteSpace(c)).ToArray());


                    if (pwtest.Any(char.IsUpper) &&
                        pwtest.Any(char.IsLower) &&
                        pwtest.Any(char.IsDigit) &&
                        pwtest != withoutSpecial)


                    {
                        //password clears complexity test
                    }

                    else

                    {
                        ViewBag.error = "Your password must contain upper and lowercase letters, numbers and special characters.";
                        return(View());
                    }



                    List <User> matches = context.Members.Where(c => c.Email == addUserViewModel.email).ToList();

                    if (matches.Count > 0)

                    {
                        ViewBag.error = "That email is already in our system.";
                        return(View());
                    }

                    string passobj = "cheese" + addUserViewModel.password;

                    Hashobject newhash = new Hashobject(passobj);
                    string     Hash    = newhash.Hashedstring(passobj);

                    User newuser = new User(addUserViewModel.username, addUserViewModel.email, Hash);

                    currentuser = newuser;
                    context.Members.Add(newuser);
                    context.SaveChanges();
                    Loggedin = "true";
                    return(Redirect("/Home/Registered"));
                }

                else
                {
                    return(View());
                }
            }

            else
            {
                return(View());
            }
        }