all groups > dotnet security > august 2004 >
You're in the

dotnet security

group:

Windows Identity


Windows Identity Ivan G.
8/18/2004 12:30:51 PM
dotnet security: Hi.

How can I create an instance of WindowsIdentity class knowing user
samaccountname and domain password?

Thanx.

Re: Windows Identity richlm
8/18/2004 7:55:46 PM
If you are using Win2003 you could use:
new WindowsIdentity(string upn)

Note that this does not even require the password - it implies that you
trust the process that is doing this.
The ramifications of this are described in detail here:
http://msdn.microsoft.com/msdnmag/issues/03/04/SecurityBriefs/default.aspx

The constructor will throw an exception if you call it on XP (which makes
things difficult if that's your development platform).


The other approach is to use WindowsIdentity.Impersonate.
You first need to get hold of the security token for the user by calling the
LoginUser Win32 API function.
There's a complete code listing on MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsIdentityClassImpersonateTopic.asp

Note that LogonUser requires SE_TCB privilege on Win2K

Hope that helps.
Richard.

[quoted text, click to view]

AddThis Social Bookmark Button