https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b4969dc0d729e913a3aa5…
commit b4969dc0d729e913a3aa593e9ddc4dbb12b432c6
Author:     Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Sat Jul 7 22:06:08 2018 +0200
Commit:     Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Mon Jul 9 05:56:40 2018 +0200
    [NET] Implement the undocumented /RANDOM option to generate random passwords
---
 base/applications/network/net/cmdUser.c | 45 +++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
diff --git a/base/applications/network/net/cmdUser.c
b/base/applications/network/net/cmdUser.c
index 3ee392b6c5..7750d247da 100644
--- a/base/applications/network/net/cmdUser.c
+++ b/base/applications/network/net/cmdUser.c
@@ -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);