public async Task <ActionResult> Authenticate(string username, string password, string returnURL = "")
        {
            var authorizedUserIDs = db.Users.Select(o => o.UserId);   //authorized users

            if (!authorizedUserIDs.Contains(username))
            {
                TempData["loginfailed"] = "You are not Authorized to login. Please Contact Admin.";
                return(RedirectToAction("LoginForm", "Login"));
            }
            if (LDAP.Authenticate(username, password))
            {
                var claims = new List <Claim>   //create a Claims list.
                {
                    new Claim(ClaimTypes.Name, username)
                };
                //build an identity, a principal, and then set the cookie using the SignInAsync method.
                ClaimsIdentity  userIdentity = new ClaimsIdentity(claims, "login");
                ClaimsPrincipal principal    = new ClaimsPrincipal(userIdentity);

                await HttpContext.SignInAsync(principal);

                if (returnURL != null && returnURL.ToString() != "")
                {
                    //System.Diagnostics.Debug.WriteLine("!!!!!!!!!!!!!!!!!1" + returnURL);
                    UserLogs u = new UserLogs(db);
                    u.LogDetails(username, IPAddress, "Logged In");
                    return(Redirect(returnURL));
                }
                else
                {
                    UserLogs u = new UserLogs(db);
                    u.LogDetails(username, IPAddress, "Logged In");
                    TempData["msg"] = "Login Successfull";
                    return(RedirectToAction("Index", "Home"));
                }
            }

            else
            {
                TempData["loginfailed"] = "Invalid username/ password";
                return(RedirectToAction("LoginForm", "Login"));
            }
        }