Q> Как,зная имя и пароль пользователя и не имея привилегий для LogonUser(),
программно проверить их на правильность?

A> Наиболее просто это воспользоваться NetUserChangePassword()

#include <afxwin.h>
#include <lm.h>
//#include <stdio.h>
#include <conio.h>

#pragma comment(lib,"netapi32")

//------------------------------------------------
void main(void)
{
char UserName[MAX_PATH];
char Password[MAX_PATH];
char CompName[MAX_PATH];

char tmp[MAX_PATH];
strcpy(tmp,"\\\\");
printf("Computer:");
scanf("%s",CompName);

if(CompName[0]!='\\')
{
strcat(tmp,CompName);
strcpy(CompName,tmp);
}

printf("User Name:");
scanf("%s",UserName );

printf("Password:");

char ch;
UINT u=0;

do
{

ch = _getch();
if(ch=='\b')
{
_putch('\b');
u--;
}
else
{

if(ch!='\r')_putch( '*' );
Password[u]=ch;
u++;
}
} while( ch != '\r' );
printf("\n");
Password[--u]=0;u=0;

wchar_t wcompname[MAX_PATH];
wchar_t wusername[MAX_PATH];
wchar_t wpassword[MAX_PATH];

mbstowcs( wcompname, CompName, strlen(CompName)+1 );
mbstowcs( wusername, UserName, strlen(UserName)+1 );
mbstowcs( wpassword, Password, strlen(Password)+1 );

switch(NetUserChangePassword(wcompname,wusername,wpassword,wpassword))
{
case ERROR_ACCESS_DENIED:
printf("The user does not have access to the requested information.\n");
break;
case NERR_InvalidComputer:
printf("The computer name is invalid.\n");
break;
case NERR_NotPrimary:
printf("The operation is allowed only on the primary domain controller of the domain.\n");
break;
case NERR_UserNotFound:
printf("The user name could not be found.\n");
break;
case NERR_PasswordTooShort:
printf("The password is shorter than required.\n");
break;
case 0:
printf("User Ok\n");
break;

default:printf ("Error\n");;
}

}


Рейтинг@Mail.ru be number one Submitter.ru - Promoting!
Хостинг от uCoz