【问题标题】:Generate password for AD user account that meets complexity policy为满足复杂性策略的 AD 用户帐户生成密码
【发布时间】:2015-07-18 03:34:33
【问题描述】:

我需要自动创建AD 用户。问题是,确保生成的密码符合AD 的密码策略。我不知道政策是什么,有没有办法在运行时确定?这是我正在使用的,但您可以看到复杂性对于 length=164 non-alphanumeric chars 是静态的,并且可能并不总是有效。我正在寻找一种从AD 获取密码策略的方法,以便生成的密码正确。

UserPrincipal up = new UserPrincipal(oPrincipalContext);                        
                    up.SamAccountName = userId;
                    up.SetPassword(System.Web.Security.Membership.GeneratePassword(16, 4));                        
                    up.Enabled = false;
                    up.ExpirePasswordNow();    
                    up.Save();

【问题讨论】:

    标签: c# .net active-directory directoryservices


    【解决方案1】:

    这就是我正在使用的。我使用DirectoryEntry/LDAP 获取密码属性,然后使用这些属性创建密码。

    DirectoryEntry child = new DirectoryEntry("LDAP://machine/DC=domain,DC=com");
    int minPwdLength = (int)child.Properties["minPwdLength"].Value;
    int pwdProperties = (int)child.Properties["pwdProperties"].Value;
    

    创建密码时使用属性。

    UserPrincipal up = new UserPrincipal(oPrincipalContext);                        
                    up.SamAccountName = userId;
                    up.SetPassword(System.Web.Security.Membership.GeneratePassword(minPwdLength,
                                       pwdProperties));                        
                    up.Enabled = true;
                    up.ExpirePasswordNow();    
                    up.Save();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-03
      • 1970-01-01
      • 2019-01-29
      • 1970-01-01
      • 2015-01-04
      • 1970-01-01
      • 2020-05-31
      相关资源
      最近更新 更多