Ejemplo n.º 1
0
 public bool IsAuthenticated(String usr, String password)
 {
     try
     {
         var aDirV = new ActiveDirectoryValidator(_path_LDAP);
         return(aDirV.IsAuthenticated(_domainName, usr, password));
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
 public bool IsAuthenticated(String usr, String password)
 {
     try
     {
         var aDirV = new ActiveDirectoryValidator(_path_LDAP);
         return aDirV.IsAuthenticated(_domainName, usr, password);
     }
     catch (Exception)
     {
         return false;
     }
 }
Ejemplo n.º 3
0
    private void AutenticateUser(string domainName, string userName, string password)
    {
        // Path to you LDAP directory server.
        // Contact your network administrator to obtain a valid path.


        string adPath = "LDAP://corp.nutanix.com";
        ActiveDirectoryValidator adAuth = new ActiveDirectoryValidator(adPath);

        if (true == adAuth.IsAuthenticated(domainName, userName, password))
        {
            // Create the authetication ticket
            FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddMinutes(60), false, "");
            // Now encrypt the ticket.
            string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
            // Create a cookie and add the encrypted ticket to the
            // cookie as data.
            HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
            // Add the cookie to the outgoing cookies collection.
            HttpContext.Current.Response.Cookies.Add(authCookie);
            // Redirect the user to the originally requested page
            HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(userName, false));
        }
    }
Ejemplo n.º 4
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                //return View(model);
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            string adPath;

            if (model.Domain == "ICRAF")
            {
                adPath = "LDAP://" + ConfigurationManager.AppSettings["ADPath"];
            }
            else
            {
                adPath = "LDAP://" + ConfigurationManager.AppSettings["ADPath2"];
            }

            ActiveDirectoryValidator adAuth = new ActiveDirectoryValidator(adPath);
            bool IsAuthenticated            = true;// adAuth.IsAuthenticated(model.Domain, model.Email, model.Password);

            switch (IsAuthenticated)
            {
            case true:
                FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, model.Email, DateTime.Now, DateTime.Now.AddMinutes(60), false, "");
                // Now encrypt the ticket.
                string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                // Create a cookie and add the encrypted ticket to the
                // cookie as data.
                HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                // Add the cookie to the outgoing cookies collection.
                System.Web.HttpContext.Current.Response.Cookies.Add(authCookie);
                // Redirect the user to the originally requested page
                //Response.Write(returnUrl);
                //Response.End();
                //return RedirectToAction("Home", "Index");
                //return RedirectToLocal(returnUrl);
                System.Web.HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(model.Email, false));
                //break;
                return(View());

            default:
                ModelState.AddModelError("", "Login failed. Please try again.");
                return(View(model));
            }

            //return View();
            //if (true == adAuth.IsAuthenticated(model.Domain, model.Email, model.Password))
            //{
            //    // Create the authetication ticket
            //    FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, model.Email, DateTime.Now, DateTime.Now.AddMinutes(60), false, "");
            //    // Now encrypt the ticket.
            //    string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
            //    // Create a cookie and add the encrypted ticket to the
            //    // cookie as data.
            //    HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
            //    // Add the cookie to the outgoing cookies collection.
            //    System.Web.HttpContext.Current.Response.Cookies.Add(authCookie);
            //    // Redirect the user to the originally requested page
            //    System.Web.HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(model.Email, false));
            //    //Response.Redirect("Default?msgs=" + "SuccessLogin");
            //}
            //else
            //{
            //    ViewBag.Message = "Login failed. Please try again.";
            //    ModelState.AddModelError("", "Invalid login attempt.");
            //    return View(model);
            //}
        }