10
10
11
11
#include "net.h"
12
12
13
+ static WCHAR szPasswordChars [] = L"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%_-+:" ;
14
+
13
15
static
14
16
int
15
17
CompareUserInfo (const void * a , const void * b )
@@ -356,6 +358,35 @@ ReadPassword(
356
358
}
357
359
358
360
361
+ static
362
+ VOID
363
+ GenerateRandomPassword (
364
+ LPWSTR * lpPassword ,
365
+ LPBOOL lpAllocated )
366
+ {
367
+ LPWSTR pPassword = NULL ;
368
+ INT nCharsLen , i , nLength = 8 ;
369
+
370
+ srand (GetTickCount ());
371
+
372
+ pPassword = HeapAlloc (GetProcessHeap (),
373
+ HEAP_ZERO_MEMORY ,
374
+ (nLength + 1 ) * sizeof (WCHAR ));
375
+ if (pPassword == NULL )
376
+ return ;
377
+
378
+ nCharsLen = wcslen (szPasswordChars );
379
+
380
+ for (i = 0 ; i < nLength ; i ++ )
381
+ {
382
+ pPassword [i ] = szPasswordChars [rand () % nCharsLen ];
383
+ }
384
+
385
+ * lpPassword = pPassword ;
386
+ * lpAllocated = TRUE;
387
+ }
388
+
389
+
359
390
INT
360
391
cmdUser (
361
392
INT argc ,
@@ -368,6 +399,7 @@ cmdUser(
368
399
#if 0
369
400
BOOL bDomain = FALSE;
370
401
#endif
402
+ BOOL bRandomPassword = FALSE;
371
403
LPWSTR lpUserName = NULL ;
372
404
LPWSTR lpPassword = NULL ;
373
405
PUSER_INFO_4 pUserInfo = NULL ;
@@ -428,6 +460,12 @@ cmdUser(
428
460
bDomain = TRUE;
429
461
#endif
430
462
}
463
+ else if (_wcsicmp (argv [j ], L"/random" ) == 0 )
464
+ {
465
+ bRandomPassword = TRUE;
466
+ GenerateRandomPassword (& lpPassword ,
467
+ & bPasswordAllocated );
468
+ }
431
469
}
432
470
433
471
if (bAdd && bDelete )
@@ -616,6 +654,13 @@ cmdUser(
616
654
ConPrintf (StdOut , L"Status: %lu\n" , Status );
617
655
}
618
656
657
+ if (Status == NERR_Success &&
658
+ lpPassword != NULL &&
659
+ bRandomPassword == TRUE)
660
+ {
661
+ ConPrintf (StdOut , L"The password for %s is: %s\n" , lpUserName , lpPassword );
662
+ }
663
+
619
664
done :
620
665
if ((bPasswordAllocated != FALSE) && (lpPassword != NULL ))
621
666
HeapFree (GetProcessHeap (), 0 , lpPassword );
0 commit comments