.net - Validate Windows username/pwd as having Admin privs -
i'm writing windows forms app runs non-privileged user account.
for 1 action, need prompt username/pwd business relationship admin privs.
so, app doesn't have run privileged account; user has specify admin business relationship in order allowed actions.
does know how validate username/pwd business relationship has admin privs?
as harry johnston commented, can utilize next authenticate username/password:
private declare auto function closehandle lib "kernel32.dll" (byval clstokentoclose intptr) integer private declare auto function logonuser lib "advapi32.dll" ( _ byval lpszusername string, _ byval lpszdomain string, _ byval lpszpassword string, _ byval dwlogontype integer, _ byval dwlogonprovider integer, _ byref phtoken intptr) boolean const domain_name string = "mydomain" dim token intptr 'use win32api logonuser authenticate username , password. 'if successful, token representing user returned. if logonuser("username", domain_name, "password", logon32_logon_batch, logon32_provider_default, token) 'the token used create windowsidentity, in turn 'used create windowsprincipal. windowsprincipal checked 'to see if belongs desired grouping in activedirectory. dim wident new windowsidentity(token) dim wprincipal new windowsprincipal(wident) if wprincipal.isinrole("administrators") 'user has admin privilege, carry on. end if closehandle(token) end if be sure replace "administrators" in wprincipal.isinrole phone call grouping want check against.
.net vb.net windows windows-authentication
No comments:
Post a Comment