Use default credentials to call DirectoryEntry

I work on the login page and the logic is similar to →

try { DirectoryEntry LDAPLogin = new DirectoryEntry(ConfigurationSettings.AppSettings ["LDAPPath"].ToString(), Usuario, Txt_Contrasenia.Text.ToString()); if (LDAPLogin.NativeGuid != LDAPLogin.Name) ValidarGrupo(); } catch (Exception exc) { Label_Info.Text = "Sus credenciales no son validas: " + Usuario.ToString() + " " + exc.Message; } 

If the user enters the credentials of rights, I call the ValidarGrupo method, which implements a search in AD for a group of users

I would like to replace the username and password with UseDefaultCredentials to avoid the user entering the username and password, and the login credentials of the user who is the login on the machine are used.

+4
source share
1 answer

I would like to replace the username and password with UseDefaultCredentials in order to avoid the username and password and login page using the credentials of the user this is the login on the machine.

So, do you really want to check if the current user is valid?

I believe that you can simply create a DirectoryEntry without specifying a username / password - in this case, System.DirectoryServices will automatically use the current user credentials:

 string ldapPath = ConfigurationSettings.AppSettings ["LDAPPath"]; DirectoryEntry LDAPLogin = new DirectoryEntry(ldapPath); 

That should be enough, I believe!

+2
source

Source: https://habr.com/ru/post/1306297/


All Articles