jakeyjia

i have a application need to verify by the string of current User Name & PWD.
maybe it can not to get the PWD but it's should be get the User Name.

i wonder to konw how
how can i get the User Name programmatically

show me, please~


i remember that under Win2000, there is an API :
Code Snippet
BOOLEAN GetUserNameEx(
EXTENDED_NAME_FORMAT NameFormat, // name format
LPTSTR lpNameBuffer, // name buffer
PULONG nSize // size of name buffer
);



it can retrieves the name of the user or other security principal associated with the calling thread.

but under the Vista, how


Re: Security for Applications in Windows Vista How to get current user name

wolf777

Does the GetUserNameEx() function not work on Vista I think there is no reason for it to not work. I am not 100% sure about this particular function, but I use GetComputerName() and there is no problem.

As for the password checking - you are right that you can't retrieve a password like you retrieve the user or computer name. But you can call LogonUser() function. You simply call it like this:

::LogonUser(username,domain,password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hToken)

If the function succeeds, you can be sure that the specified username & password is correct.




Re: Security for Applications in Windows Vista How to get current user name

jakeyjia

thank you ! i can get the UserName.

I can get current User Name by using :
BOOL GetUserName(
LPTSTR lpBuffer, // name buffer
LPDWORD nSize // size of name buffer
);


but how to get the password i know that under Windows2000, we can get it by rewrite the GINA.
but i know there have changed GINA to Windows Vista Credential Provider.

anybody have some hint to me






Re: Security for Applications in Windows Vista How to get current user name

wolf777

AFAIK you can get the password only by asking the user to enter it. Of course, if you write a Credential Provider then you get it by design.




Re: Security for Applications in Windows Vista How to get current user name

jakeyjia

ok~ i know~

is there any other way to solve

Credential Provider is a bit complex to me~






Re: Security for Applications in Windows Vista How to get current user name

wolf777

jakeyjia wrote:

is there any other way to solve



No other way AFAIK.

jakeyjia wrote:

Credential Provider is a bit complex to me~



So simply ask user to enter his password in some editbox (set it with ES_PASSWORD style). Then you can use LogonUser() function to check if the entered password is correct.




Re: Security for Applications in Windows Vista How to get current user name

jakeyjia

wolf777 wrote:
Then you can use LogonUser() function to check if the entered password is correct.

thank wolf!

i think i have got the target by LogonUser() under Vista.




Re: Security for Applications in Windows Vista How to get current user name

wolf777

jakeyjia wrote:

i want to know how to set the SE_TCB_NAME privilege under Windows2000.

You will need to use AdjustTokenPrivileges() function. See http://msdn2.microsoft.com/en-us/library/aa446619.aspx, there is a sample helper function which you can simply copy&paste.

The function should be then used on your process token like this:

Code Snippet

HANDLE hProc, hProcToken;
hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
if (hProc)
if (OpenProcessToken(hProc, TOKEN_ADJUST_PRIVILEGES, &hProcToken))
SetPrivilege(hProcToken, SE_TCB_NAME, true);





Re: Security for Applications in Windows Vista How to get current user name

rpolansky

Check out implementing NPLogonNotify. This and NPPasswordChangeNotify are still supporting in Vista and easier to implement than a Credential Provider. Moreover, if you only want to get the user and not participate in the authentication process itself, then that's more appropriate. But since you don't describe how and when you'll use this information, I don't know if this function will help.

-Rob