Click here to Skip to main content
Licence CPOL
First Posted 13 Aug 2007
Views 39,106
Bookmarked 22 times

How to Detect Empty Password Users

By | 13 Aug 2007 | Article
This article describes how to detect empty password users

Introduction

This article describes how to detect empty password users in the Windows NT environment using Visual C++ 6. This method may require the Platform SDK.

Requisite Knowledge

Readers should be familiar with the C++ language and Windows API. This article is so simple that you can understand it even if you are not a professional.

Empty Password Users: Why We Detect Them

Empty password users can destroy local computers because a WORM VIRUS is able to use such accounts to spread itself. When you turn your system on without a password, your system infects within a minute. For this reason, if you can detect empty passwords, you can advise the user to set a password. In the past I searched Google for how to deal with this, but I could not get anything about it. So, I decided to write my own program. This is some simple empty password detection code that runs on Windows NT; it does not support Windows 9x.

What is the Problem?

The first idea is using the LogonUser API. This API can log in a given user name and return a result. The first code example is:

HANDLE hToken = NULL;
BOOL bLoggedOn = ::LogonUser(pszUserName, pszPassword, NULL, 
    LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hToken);

if(bLoggedOn) 
{
    printf("Logged On!\n");
} 
else 
{
    printf("Failed\n");
}

However, the first code's problem is that the LogonUser API does not work with an empty password. We cannot call this function with a NULL password or "". In this situation, how can we detect an empty password? The answer is simple: just check the error code. In MSDN, LogonUser returns the error code via GetLastError. So, we can get LogonUser's error by using the GetLastError function. The following code describes how to get the error code of LogonUser.

HANDLE hToken = NULL; 
BOOL bLoggedOn = ::LogonUser(pszUserName, "", NULL, 
    LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hToken);
DWORD dwError = GetLastError();

dwError has the error code of LogonUser. LogonUser returns error code 1327 when a user has an empty password. I tested the following code from Windows XP on my own system and it works well.

HANDLE hToken = NULL; 
BOOL bLoggedOn = ::LogonUser(pszUserName, "", 
    NULL, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, 
&hToken);
DWORD dwError = GetLastError();

if(bLoggedOn || dwError == 1327)
{
    printf("Empty Password Logon User: %s\n", pszUserName);
}

History

  • 13 August, 2007 -- Original version posted

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Yonghwi Kwon

Software Developer

Korea (Republic Of) Korea (Republic Of)

Member

I started to write software since 1999 and have developed various products including security solutions and system utilities.
 
Microsoft Visual C++ MVP (from 2008 to present)
Website: http://rodream.net

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralDomain user gets locked out PinmemberDuggi22:01 18 Dec '07  
GeneralRe: Domain user gets locked out PinmemberKwon Yong Hwi14:35 19 Dec '07  
GeneralRe: Domain user gets locked out Pinmemberjamalhaider19:52 18 Jun '08  
GeneralRe: Domain user gets locked out PinmemberDuggi0:44 22 Oct '08  
GeneralEach test will add two entries in eventviewer PinmemberRalf Lohmueller19:32 5 Sep '07  
GeneralError 1327 PinmvpDavidCrow3:32 21 Aug '07  
GeneralRe: Error 1327 PinmemberKwon Yong Hwi3:20 22 Aug '07  
GeneralGreat tip! PinmemberGrump23:01 20 Aug '07  
GeneralRe: Great tip! PinmemberKwon Yong Hwi3:19 22 Aug '07  
GeneralGood one! PinmemberVasudevan Deepak Kumar1:59 16 Aug '07  
GeneralRe: Good one! PinmemberAnand Todkar5:01 16 Aug '07  
General:confused: Wrong code is found Pinmemberj2doll19:23 13 Aug '07  
GeneralRe: :confused: Wrong code is found [modified] PinmemberKwon Yong Hwi20:03 13 Aug '07  
Generalnice one. I will try it PinmemberMichael Sync17:06 13 Aug '07  
GeneralRe: nice one. I will try it PinmemberKwon Yong Hwi22:21 13 Aug '07  
GeneralRe: nice one. I will try it PinmemberMichael Sync0:10 14 Aug '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 13 Aug 2007
Article Copyright 2007 by Yonghwi Kwon
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid