By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,212 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,212 IT Pros & Developers. It's quick & easy.

Reading System.Byte[] Value from AD

P: n/a
Hi all,

I am writng some code to read AD user properties but I am not having much
luck reading octet values. For example, there is a property userPassword
which returns System.Byte[].

When I use ADSIEDIT, I can see the value in the format 0x077 0x043 0x064
0x055 0x072 0x054 0x44 0x058 which I can convert by using Character Map.

Does anyone know how I can get the value of this property.

Regards,

Pere

PS: I am very new to C#

Jun 17 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Pere,

System.Text.Encoding.Default.GetString(bytes);

You can replace "Default" with any of ASCII, UTF32, UTF8, UTF7, Unicode and
BigEndianUnicode if you'd like to match the appropriate encoding.

HTH

"Pere Raphael" <Pe**@community.nospam> wrote in message
news:uY**************@TK2MSFTNGP03.phx.gbl...
Hi all,

I am writng some code to read AD user properties but I am not having much
luck reading octet values. For example, there is a property userPassword
which returns System.Byte[].

When I use ADSIEDIT, I can see the value in the format 0x077 0x043 0x064
0x055 0x072 0x054 0x44 0x058 which I can convert by using Character Map.

Does anyone know how I can get the value of this property.

Regards,

Pere

PS: I am very new to C#

Jun 17 '06 #2

P: n/a
Hi Dave,

Thanks for your reply.
I tried the suggestion but I get an error message.
It's possible that I have not explained my problem clearly.
Please the relevant part of my code.
When I get the AD search result for user with "surname", I display the user's CN and userPassword.
Instead of being shown the password, I get System.Byte[].
Apparently adObject.Properties["userPassword"][0] is an object so can't convert to string.
Hope you're able to help.

Basicly trying to write code to email user's password to the user.

Thanks again,

Pere

DirectorySearcher adSearcherObject = new DirectorySearcher(adFolderObject);
adSearcherObject.SearchScope = SearchScope.Subtree;
Console.Write("Enter name to search for: ");
surname = Console.ReadLine();

adSearcherObject.Filter = "(&(ObjectClass=user)(sn=" + surname + "))";

foreach (SearchResult adObject in adSearcherObject.FindAll())
{
count++;
found = true;
Console.WriteLine("CN={0}", adObject.Properties["CN"][0]);
PasswordString = System.Text.Encoding.Default.GetString(adObject.Pr operties["userPassword"][0]);
Console.WriteLine(PasswordString);

"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message news:O2**************@TK2MSFTNGP03.phx.gbl...
Hi Pere,

System.Text.Encoding.Default.GetString(bytes);

You can replace "Default" with any of ASCII, UTF32, UTF8, UTF7, Unicode and
BigEndianUnicode if you'd like to match the appropriate encoding.

HTH

"Pere Raphael" <Pe**@community.nospam> wrote in message
news:uY**************@TK2MSFTNGP03.phx.gbl...
Hi all,

I am writng some code to read AD user properties but I am not having much
luck reading octet values. For example, there is a property userPassword
which returns System.Byte[].

When I use ADSIEDIT, I can see the value in the format 0x077 0x043 0x064
0x055 0x072 0x054 0x44 0x058 which I can convert by using Character Map.

Does anyone know how I can get the value of this property.

Regards,

Pere

PS: I am very new to C#


Jun 17 '06 #3

P: n/a
Have you visit here?
http://www.microsoft.com/technet/scr...s/default.mspx

chanmm
"Pere Raphael" <Pe**@community.nospam> wrote in message news:uE**************@TK2MSFTNGP04.phx.gbl...
Hi Dave,

Thanks for your reply.
I tried the suggestion but I get an error message.
It's possible that I have not explained my problem clearly.
Please the relevant part of my code.
When I get the AD search result for user with "surname", I display the user's CN and userPassword.
Instead of being shown the password, I get System.Byte[].
Apparently adObject.Properties["userPassword"][0] is an object so can't convert to string.
Hope you're able to help.

Basicly trying to write code to email user's password to the user.

Thanks again,

Pere

DirectorySearcher adSearcherObject = new DirectorySearcher(adFolderObject);
adSearcherObject.SearchScope = SearchScope.Subtree;
Console.Write("Enter name to search for: ");
surname = Console.ReadLine();

adSearcherObject.Filter = "(&(ObjectClass=user)(sn=" + surname + "))";

foreach (SearchResult adObject in adSearcherObject.FindAll())
{
count++;
found = true;
Console.WriteLine("CN={0}", adObject.Properties["CN"][0]);
PasswordString = System.Text.Encoding.Default.GetString(adObject.Pr operties["userPassword"][0]);
Console.WriteLine(PasswordString);

"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message news:O2**************@TK2MSFTNGP03.phx.gbl...
Hi Pere,

System.Text.Encoding.Default.GetString(bytes);

You can replace "Default" with any of ASCII, UTF32, UTF8, UTF7, Unicode and
BigEndianUnicode if you'd like to match the appropriate encoding.

HTH

"Pere Raphael" <Pe**@community.nospam> wrote in message
news:uY**************@TK2MSFTNGP03.phx.gbl...
Hi all,

I am writng some code to read AD user properties but I am not having much
luck reading octet values. For example, there is a property userPassword
which returns System.Byte[].

When I use ADSIEDIT, I can see the value in the format 0x077 0x043 0x064
0x055 0x072 0x054 0x44 0x058 which I can convert by using Character Map.

Does anyone know how I can get the value of this property.

Regards,

Pere

PS: I am very new to C#


Jun 18 '06 #4

P: n/a
Hi Chanmm,

The User-Password attribute in AD is a write-only property. The password is
encrypted and stored. You cannot get decrypted text, instead, you can only
have this user reset password. Please check the following link for more
information about the User-Password attribute.

http://msdn.microsoft.com/library/de...us/adschema/ad
schema/a_userpassword.asp

Kevin Yu
Microsoft Online Community Support

================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jun 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.