当前位置:编程学习 > C#/ASP.NET >>

关于修改域帐户密码,并且用域帐户登陆的问题

这是修改域帐户的代码
 try
                        {
                            DirectoryEntry de = new DirectoryEntry("LDAP://192.168.0.5", "clusterAdmin", "Ca123456");

                            DirectorySearcher deSearch = new DirectorySearcher(de);
                            deSearch.Filter = "(&(&(objectCategory=person)(objectClass=user))(sAMAccountName=" + ut.U_LoginName + "))";
                            deSearch.SearchScope = SearchScope.Subtree;
                            SearchResult result = deSearch.FindOne();
                            DirectoryEntry de1 = result.GetDirectoryEntry();
                            object retResult = de1.Invoke("SetPassword", ReNew_U_Password_Value);
                            de1.CommitChanges();
                            ut.U_Password = New_U_Password_Value;
                            de1.Close();
                            de.Close();
                            de1.Dispose();
                            de.Dispose();
                            deSearch.Dispose();
                        }
                        catch (Exception ex)
                        {
                            DispTxt = "修改AD域帐户发生异常";
                         
                        }


  using (DirectoryEntry de = new DirectoryEntry("LDAP://192.168.0.5",LoginName,LoginPassWord))
            {
              
                DirectorySearcher mySearch = new DirectorySearcher(de);

                mySearch.Filter = "(&(&(objectCategory=person)(objectClass=user))(sAMAccountName=" + LoginName + "))";
                mySearch.SearchScope = SearchScope.Subtree;
                try
                {
                    SearchResultCollection results = mySearch.FindAll();
                    if (results.Count > 0)
                    {
                        temp = 1;//成功登陆,帐户与密码匹配。


                          foreach (SearchResult res in mySearch.FindAll())
                          {
                              UserInfo = res.GetDirectoryEntry().Properties["distinguishedname"][0].ToString();
                          }
                            
                        string[] tempinfo=UserInfo.Split(',');
                        if (tempinfo.Length >= 2)
                        {
                            if (tempinfo[0].Substring(0, 3) == "CN=")
                            Cname= tempinfo[0].Substring(3);
                            if (tempinfo[1].Substring(0, 3) == "OU=")
                            Group = tempinfo[1].Substring(5);

                            if (Group != string.Empty)
                            {
                                GroupId = BusinessFacade.GetGroupID(Group);
                                if (GroupId == -1)
                                {
                                    sys_GroupTable tempgroup = new sys_GroupTable();
                                    tempgroup.G_CName = Group;
                                    tempgroup.DB_Option_Action_ = "Insert";
                                    BusinessFacade.sys_GroupInsertUpdate(tempgroup);
                                }
                                GroupId = BusinessFacade.GetGroupID(Group);
                            }
                         }


                    }
                    else
                    {
                        temp = 2;//判断登陆用户帐户和名错误
                    
                    }
                    de.Close();
                    de.Dispose();
                    mySearch.Dispose();
                }
                catch (Exception ex)
                {
                    temp = 3;
                    de.Close();
                    de.Dispose();
                    mySearch.Dispose();
                }

第一片是我修改域帐户密码,第二片是我登陆用来验证的代码.发现一个问题,域密码修改后,登陆系统的时老密码和新密码都能使用.如果清空IE又一切恢复正常.我想问下是我代码问题还是哪些地方需要配置
补充:.NET技术 ,  非技术区
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,