Beispiel #1
0
        protected void btnSync_Click(object sender, EventArgs e)
        {
            SyncADInfoComponent sync = new SyncADInfoComponent();

            sync.SyncADInfo(SPContext.Current.Site.Url);
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "setvsel", "layer.closeAll();", true);
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "setAllsel", "BindSelectAllEvent();", true);
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "setsel", "BindEachCboEvent();", true);
        }
Beispiel #2
0
        private bool ChangeUserPassword(string NewPwd, string oldPwd)
        {
            Impersonator impersonator = new Impersonator();
            bool         result       = false;

            try
            {
                impersonator.BeginImpersonation();

                string password  = ConfigurationSettings.AppSettings["CMICTADPasseord"].ToString();
                string domain    = ConfigurationSettings.AppSettings["CMICTDomainName"].ToString();
                string userName  = ConfigurationSettings.AppSettings["CMICTADUser"].ToString();
                string container = ConfigurationSettings.AppSettings["CMICTLDAPDomain"].ToString();

                SyncADInfoComponent sync = new SyncADInfoComponent();
                string loginName         = GetLoginName();

                using (PrincipalContext context = GetPContext(oldPwd, domain, loginName, container))
                {
                    using (UserPrincipal principal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, loginName))
                    {
                        ////重置用户密码
                        //result = sync.ChangeUserPassword(loginName, NewPwd);

                        //if (!principal.UserCannotChangePassword)
                        //{
                        //    principal.UserCannotChangePassword = true;
                        //}
                        principal.ChangePassword(oldPwd, NewPwd);

                        //principal.SetPassword(NewPwd);
                        principal.Save();

                        result = true;
                    }
                }
                if (impersonator.IsImpersonated)
                {
                    impersonator.StopImpersonation();
                }
            }
            catch (Exception ex)
            {
                BaseComponent.Error("用户密码重置: " + ex.Message + "--------" + ex.StackTrace);

                if (impersonator.IsImpersonated)
                {
                    impersonator.StopImpersonation();
                }
            }

            return(result);
        }