从C#更改域密码 [英] change domain password from c #

查看:75
本文介绍了从C#更改域密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚安,感谢您的合作,我不会说英语,但对论坛很熟悉,非常好.可以帮助我解决我的问题.我有一个应用程序,允许用户更改在c#中创建的域的密码,效果很好,但是现在我必须遵守实施该密码的公司的政策.我需要用户更改其密码,但是要使用不同的密码(安全策略).我使用此代码执行此操作,但是可以在不验证使用的密码历史记录的情况下放置相同的密钥.我无法使用数据库存储用户密码.下面的代码:

good night thank you for your cooperation, I do not speak English but am familiar with the forum and is very good. Could help me with my problem. I have an application that allows users to change passwords of domain created in c # works perfectly but now I must abide by the policies of the company where it is implemented. I need users to change their password but a different and not the same (security policies). I do it with this code, which works but I can put the same key without validating the password history used. I can not use a database to store user passwords. The code below:

private void resetearContraseñaEnPdc(string usuario, string scontraseña)
    {
        Forest forest = Forest.GetForest(forestContext); 
        string pdc = forest.SchemaRoleOwner.Name.ToString(); 
        object ocontraseña = scontraseña;

       
            DirectoryEntry entry = conexldap.conexionConControladorVariable(pdc);//aqui me conecto con el directorio activo. 
            DirectorySearcher search = new DirectorySearcher(entry);
            search.Filter = "sAMAccountName=" + usuario;
            result = search.FindOne();          

        
        if (result != null)
        {
            try
            {
                                               
                entry = result.GetDirectoryEntry();
                entry.Invoke("SetPassword", ocontraseña);
                entry.CommitChanges();
                entry.Close();
            }
            catch(Exception ex)
            {
                
                throw new Exception("La contraseña no cumple con las políticas de seguridad, la clave debe contener mayúsculas, números o caracteres especiales.");
            }
        }
        entry.Close();

    }



非常感谢.



Thank you very much.

推荐答案


您还可以使用

You could also use
entry.Invoke("ChangePassword", new[] {oldpassword, newpassword});


当然,这需要请求当前密码,但是我的理解是,如果不符合密码策略,它将抛出异常,其中"SetPassword"更像是管理功能.

原文:

可能想看看这个.但是,这似乎只能在Server 2003+上执行,因此不确定是否适合您.

NetValidatePasswordPolicy
http://msdn.microsoft.com/en-us/library/aa370661.aspx [ ^ ]


Of course this requires requesting the current password, but my understanding is it will throw an exception if password policy is not met, where "SetPassword" is more like an administrative function.

Original:

Might want to take a look at this. However this appears to only be able to execute on Server 2003+ so not sure if this would work for you or not.

NetValidatePasswordPolicy
http://msdn.microsoft.com/en-us/library/aa370661.aspx[^]


这篇关于从C#更改域密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆