Search code examples
passwordsadmindirectoryentry

c# create Directoryentry with encrypted password


We store Administrator user and password (encrypted) in database. And want to use encrypted administrator password when using DirectoryEntry C# like this.

DirectoryEntry loginDirectory = new DirectoryEntry("ldap_path", "administrator", "Password");

how can I do it, i don't want to write admin password in code. Thanks


Solution

  • What you would do is use some form of two way encryption. You can read more about that here: Encrypt and decrypt a string

    Then you would have the encrypted string in your database and then decrypt it when you're going to use it like this:

    DirectoryEntry loginDirectory = new DirectoryEntry("ldap_path", "administrator", decrypt(database["Password"]));