DirectoryEntry.Properties["userPassword"][0]

  • Thread starter Thread starter Petra
  • Start date Start date
P

Petra

Hi

I have problem reading the userPassword - Property from an Entry with
the person-Schema using Microsoft Dotnet. I use DirectoryServices
library and LDAP in my class. The code I used is as following:

DirectoryEntry de = new
DirectoryEntry,gAllgemein.IBMLDAPServerPathBenutzer,"cn=root","ldap",AuthenticationTypes.None);
String ergebnis = aktBenutzer.Properties["userPassword"][0].ToString();

ergebnis return "System.Byte[]"

I can't read the userPassword, because i can't convert the Object into
a byte-Array.

In Visual Studio in the monitoring-Window i can ask
"aktBenutzer.Properties["userPassword"][0][0]" and i get the first
byte and so on, but not in the coding. Can you help me?

Petra
 
Petra,

All you have to do is the following:

// Cast the password to a byte array.
byte[] pbytBytes = (byte[]) aktBenutzer.Properties["userPassword"][0];

Once you have that, that should be all there is to it.

Hope this helps.
 
Nicholas Paldino said:
Petra,

All you have to do is the following:

// Cast the password to a byte array.
byte[] pbytBytes = (byte[]) aktBenutzer.Properties["userPassword"][0];

Once you have that, that should be all there is to it.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Petra said:
Hi

I have problem reading the userPassword - Property from an Entry with
the person-Schema using Microsoft Dotnet. I use DirectoryServices
library and LDAP in my class. The code I used is as following:

DirectoryEntry de = new
DirectoryEntry,gAllgemein.IBMLDAPServerPathBenutzer,"cn=root","ldap",Authent
icationTypes.None);
String ergebnis = aktBenutzer.Properties["userPassword"][0].ToString();

ergebnis return "System.Byte[]"

I can't read the userPassword, because i can't convert the Object into
a byte-Array.

In Visual Studio in the monitoring-Window i can ask
"aktBenutzer.Properties["userPassword"][0][0]" and i get the first
byte and so on, but not in the coding. Can you help me?

Petra

Thank you for your tip, but it doesn' work. i get a
System.ArgumentOutOfRangeException. Have you any other idea?

Thank
Petra
 
Back
Top