54. FAQ o Win API |
Q> As, knowing a name and the password of the user and without having privileges for LogonUser (), Program to check up them on correctness? A> it is the Most simple to use NetUserChangePassword () (If it is authorized to user to change the password) #include <windows.h>
#include <lm.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 controler 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");;
}
}
|
2000 (c) DM