Exemple #1
0
        public static void ChangePassword(AccountChangeModel model)
        {
            try
            {
                //Connect to AD through LDAP
                string path = ConfigurationManager.ConnectionStrings["ADConnectionString"].ConnectionString;
                //DirectoryEntry dEntry = new DirectoryEntry(path)
                DirectoryEntry dEntry = new DirectoryEntry(path, "AIMS\\" + model.UserID, model.Password, AuthenticationTypes.Secure);

                //Include memberOf attribute and search for user
                var obj = dEntry.NativeObject;
                DirectorySearcher dSearch = new DirectorySearcher(dEntry);
                dSearch.Filter = "(SAMAccountName=" + model.UserID + ")";
                dSearch.PropertiesToLoad.Add("cn");

                SearchResult result = dSearch.FindOne();
                if (result != null)
                {
                    DirectoryEntry userEntry = result.GetDirectoryEntry();

                    if (userEntry != null)
                    {
                        userEntry.Invoke("ChangePassword", new object[] { model.Password, model.newPassword });
                        userEntry.CommitChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
        public ActionResult Change(AccountChangeModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }
            if (model.newPassword != model.confirmPassword)
            {
                this.ModelState.AddModelError(string.Empty, "The New Password and Confirm Password do not match. Please try again.");
                return(this.View(model));
            }

            try
            {
                if (Membership.ValidateUser(model.UserID, model.Password))
                {
                    HubSecurity.ChangePassword(model);
                    model.success = true;
                    return(this.View(model));
                }
                else
                {
                    this.ModelState.AddModelError(string.Empty, "The username or password is incorrect. Please try again.");
                    return(this.View(model));
                }
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
                return(View(model));
                //return Content(ex.Message);
            }
        }
Exemple #3
0
        public ActionResult Change()
        {
            var model = new AccountChangeModel
            {
                UserID  = HttpContext.User.Identity.Name.ToString(),
                success = false
            };

            //string ftt = Session["TESTdomainPolicy"].ToString();
            ////int64 sixfour = Convert.ToInt64(ftt);
            //Int64 ft = Convert.ToInt64(ftt);
            ////TEST CODE
            //try
            //{
            //    //model.domainPolicy = DateTime.FromFileTime((long)Session["TESTdomainPolicy"]).ToShortDateString() + ' ' + DateTime.FromFileTime((long)Session["TESTdomainPolicy"]).ToShortTimeString();

            //    DateTime dt = new DateTime(1601, 01, 02).AddTicks(ft);
            //    model.domainPolicy = dt.ToString();
            //}
            //catch
            //{
            //    model.domainPolicy = "nope";
            //}
            //try
            //{
            //    //model.lastReset = DateTime.FromFileTime((long)Session["TESTlastReset"]).ToShortDateString() + ' ' + DateTime.FromFileTime((long)Session["TESTlastReset"]).ToShortTimeString();
            //    DateTime test = DateTime.FromFileTime((long)Session["TESTlastReset"]);
            //    model.lastReset = String.Format("You must change your password within" +
            //                          " {0} days"
            //                         , test);
            //}
            //catch
            //{
            //    model.lastReset = "nope";
            //}

            //model.lastReset = DateTime.FromFileTime((long)Session["TESTlastReset"]).ToShortDateString() + ' ' + DateTime.FromFileTime((long)Session["TESTlastReset"]).ToShortTimeString();
            //model.daysLeft = model.domainPolicy - DateTime.Today.Subtract(DateTime.FromFileTime((long)Session["TESTlastReset"]).Day;
            return(View(model));
        }