I have C++ code that tries to authenticate a local user to windows:
BOOL result = ::LogonUserW(localAdminUserName_.c_str(), L".", localAdminPassword_.c_str(),
LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT);
This works fine for ASCII character-set based usernames.
But doesn't work for a user named, say userああ
If I print the variable localAdminUserName_
in the log, It's printing the username just fine.
Is .c_str()
messing it up somehow?
Should I encode the username/password in someway before making this API call?
The following console application I made to test this scenario, is working fine!
_declspec(dllimport)
BOOL
__stdcall
LogonUserW(
__in LPCWSTR lpszUsername,
__in_opt LPCWSTR lpszDomain,
__in LPCWSTR lpszPassword,
__in DWORD dwLogonType,
__in DWORD dwLogonProvider,
__deref_out PHANDLE phToken
);
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hToken = NULL;
BOOL returnValue = LogonUserW(
L"userああ",
L".",
L"pa$$w0rd",
LOGON32_LOGON_NETWORK,
LOGON32_PROVIDER_DEFAULT,
&hToken);
if (returnValue == false) {
std::cout<<"Error!";
} else {
std::cout<<"Success!";
}
return 0;
}