Validate Windows User On Network In C++

Need to validate and/or impersonate a user on a Windows domain? I Googled for this a bit but the API call is fairly simple so here is a quick snippet:

HANDLE htoken = nullptr;
DWORD dwError = ERROR_SUCCESS;
BOOL retVal = LogonUserW(L"JoeUser", L"JoesDomain", L"JoesPasswordPlainText", LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, &htoken)

if (!retVal)
{
    dwError = ::GetLastError();
    qDebug() << "Error: GetLastError returned: " << dwError;
}
else
{
    ::CloseHandle(htoken);
    qDebug() << "Logon successful.";
}
Download PDF
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *