mirror of
https://github.com/reactos/reactos.git
synced 2025-01-01 12:04:51 +00:00
[NET] Implement the undocumented /RANDOM option to generate random passwords
This commit is contained in:
parent
4e45a91547
commit
b4969dc0d7
1 changed files with 45 additions and 0 deletions
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include "net.h"
|
||||
|
||||
static WCHAR szPasswordChars[] = L"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%_-+:";
|
||||
|
||||
static
|
||||
int
|
||||
CompareUserInfo(const void *a, const void *b)
|
||||
|
@ -356,6 +358,35 @@ ReadPassword(
|
|||
}
|
||||
|
||||
|
||||
static
|
||||
VOID
|
||||
GenerateRandomPassword(
|
||||
LPWSTR *lpPassword,
|
||||
LPBOOL lpAllocated)
|
||||
{
|
||||
LPWSTR pPassword = NULL;
|
||||
INT nCharsLen, i, nLength = 8;
|
||||
|
||||
srand(GetTickCount());
|
||||
|
||||
pPassword = HeapAlloc(GetProcessHeap(),
|
||||
HEAP_ZERO_MEMORY,
|
||||
(nLength + 1) * sizeof(WCHAR));
|
||||
if (pPassword == NULL)
|
||||
return;
|
||||
|
||||
nCharsLen = wcslen(szPasswordChars);
|
||||
|
||||
for (i = 0; i < nLength; i++)
|
||||
{
|
||||
pPassword[i] = szPasswordChars[rand() % nCharsLen];
|
||||
}
|
||||
|
||||
*lpPassword = pPassword;
|
||||
*lpAllocated = TRUE;
|
||||
}
|
||||
|
||||
|
||||
INT
|
||||
cmdUser(
|
||||
INT argc,
|
||||
|
@ -368,6 +399,7 @@ cmdUser(
|
|||
#if 0
|
||||
BOOL bDomain = FALSE;
|
||||
#endif
|
||||
BOOL bRandomPassword = FALSE;
|
||||
LPWSTR lpUserName = NULL;
|
||||
LPWSTR lpPassword = NULL;
|
||||
PUSER_INFO_4 pUserInfo = NULL;
|
||||
|
@ -428,6 +460,12 @@ cmdUser(
|
|||
bDomain = TRUE;
|
||||
#endif
|
||||
}
|
||||
else if (_wcsicmp(argv[j], L"/random") == 0)
|
||||
{
|
||||
bRandomPassword = TRUE;
|
||||
GenerateRandomPassword(&lpPassword,
|
||||
&bPasswordAllocated);
|
||||
}
|
||||
}
|
||||
|
||||
if (bAdd && bDelete)
|
||||
|
@ -616,6 +654,13 @@ cmdUser(
|
|||
ConPrintf(StdOut, L"Status: %lu\n", Status);
|
||||
}
|
||||
|
||||
if (Status == NERR_Success &&
|
||||
lpPassword != NULL &&
|
||||
bRandomPassword == TRUE)
|
||||
{
|
||||
ConPrintf(StdOut, L"The password for %s is: %s\n", lpUserName, lpPassword);
|
||||
}
|
||||
|
||||
done:
|
||||
if ((bPasswordAllocated != FALSE) && (lpPassword != NULL))
|
||||
HeapFree(GetProcessHeap(), 0, lpPassword);
|
||||
|
|
Loading…
Reference in a new issue