Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create WindowsIdentity using just a domain and username

I am building a site that gets user information using the WindowsIdentity of the current user. The main info I get from this is the ssid.

I do this for the current users as follows

IntPtr logonToken = WindowsIdentity.GetCurrent().Token;
WindowsIdentity windowsId = new WindowsIdentity(logonToken);
string ssid = windowsId.User.ToString();

What I need to do now, and am failing at, is getting the ssid for any arbitrary username that exists on the domain.

I tried WindowsIdentity(string), but that gave me a SecurityException

The name provided is not a properly formed account name.

like image 284
Matt Avatar asked May 09 '11 07:05

Matt


1 Answers

How are you formatting the principal? Generally they take the form of [email protected], so if your AD provides principal resolution on say example.com, a user principal name (UPN) may look like: [email protected]. The WindowsIdentity(string) constructor accepts a UPN, not an older format username EXAMPLE\joe.bloggs

like image 85
Matthew Abbott Avatar answered Sep 28 '22 01:09

Matthew Abbott