1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
   | DirectoryEntry ObjUser = new DirectoryEntry("LDAP://monIP/CN=" + MonUser + ",cheminDuUser");
 
              try
                    {
                        /* Section critique - L'utilisateur a le droit de modifier son mot de passe */
                        //ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
                        int val;
                        const long ADS_ACETYPE_ACCESS_ALLOWED = 0x00000;
                        const long ADS_ACETYPE_ACCESS_ALLOWED_OBJECT = 0x00005;
                        val = (int) ADS_ACETYPE_ACCESS_ALLOWED;                        
                        ObjUser.Properties["userAccountControl"].Value = ADS_ACETYPE_ACCESS_ALLOWED;
                        ObjUser.Properties["userAccountControl"].Value = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT;
                        //ObjUser.CommitChanges();
 
 
 
                        string dname = ObjUser.Properties["displayName"].Value.ToString();
                        string authtype = ObjUser.AuthenticationType.ToString();
 
                        ObjUser.Invoke("ChangePassword", new object[] { MonExPwd , MonPwd});                        
                        ObjUser.Properties["userAccountControl"].Value = 512;
                        ObjUser.Properties["userAccountControl"].Value = 0x0200;
                        ObjUser.Properties["pwdLastSet"].Value = 0;
 
                        // On envoie les modifications au serveur
                        string ppcache = ObjUser.UsePropertyCache.ToString();
                       // ObjUser.CommitChanges();
                        labEchecAuth.Text = "Mot de passe changé!!!";                        
                    } 
                catch (Exception ex1)
                {
 
                    ldapConn.Disconnect();
                    ldapConn2.Disconnect();
                    labEchecAuth.Text = MonUser + ex1.GetBaseException() + ex1.Message + ex1.Source;
                    return;
                } | 
Partager