mirror of
https://github.com/reactos/reactos.git
synced 2025-06-25 23:39:42 +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"
|
#include "net.h"
|
||||||
|
|
||||||
|
static WCHAR szPasswordChars[] = L"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%_-+:";
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
CompareUserInfo(const void *a, const void *b)
|
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
|
INT
|
||||||
cmdUser(
|
cmdUser(
|
||||||
INT argc,
|
INT argc,
|
||||||
|
@ -368,6 +399,7 @@ cmdUser(
|
||||||
#if 0
|
#if 0
|
||||||
BOOL bDomain = FALSE;
|
BOOL bDomain = FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
BOOL bRandomPassword = FALSE;
|
||||||
LPWSTR lpUserName = NULL;
|
LPWSTR lpUserName = NULL;
|
||||||
LPWSTR lpPassword = NULL;
|
LPWSTR lpPassword = NULL;
|
||||||
PUSER_INFO_4 pUserInfo = NULL;
|
PUSER_INFO_4 pUserInfo = NULL;
|
||||||
|
@ -428,6 +460,12 @@ cmdUser(
|
||||||
bDomain = TRUE;
|
bDomain = TRUE;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
else if (_wcsicmp(argv[j], L"/random") == 0)
|
||||||
|
{
|
||||||
|
bRandomPassword = TRUE;
|
||||||
|
GenerateRandomPassword(&lpPassword,
|
||||||
|
&bPasswordAllocated);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bAdd && bDelete)
|
if (bAdd && bDelete)
|
||||||
|
@ -616,6 +654,13 @@ cmdUser(
|
||||||
ConPrintf(StdOut, L"Status: %lu\n", Status);
|
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:
|
done:
|
||||||
if ((bPasswordAllocated != FALSE) && (lpPassword != NULL))
|
if ((bPasswordAllocated != FALSE) && (lpPassword != NULL))
|
||||||
HeapFree(GetProcessHeap(), 0, lpPassword);
|
HeapFree(GetProcessHeap(), 0, lpPassword);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue