File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Paolo Frigo, 2018
2
+ # https://www.scriptinglibrary.com
3
+
4
+ . .\New-RandomPassword.ps1
5
+
6
+ Describe " New-RandomPassword" - Tags " Unit Tests" {
7
+ it " Should generate a String" {
8
+ (New-RandomPassword ).GetType().Name | Should BeExactly " String"
9
+ }
10
+
11
+ # Pick a password lenght between 0 and 7 and 33 and 100 characters
12
+ $n = 0 .. 1 + 33 .. 100
13
+ foreach ($length in $n ){
14
+ it " Should throw an exeption if the password lenght ($length ) is out of the accepted range (8-32)" {
15
+ {New-RandomPassword - Lenght 5 } | Should throw
16
+ }
17
+ }
18
+ # Pick a password lenght between 8 and 32 characters
19
+ $n = 8 .. 32
20
+ foreach ($length in $n ){
21
+ It " Should generate a password $length character long" {
22
+ (New-RandomPassword ($length )).length | Should BeExactly " $length "
23
+ }
24
+ }
25
+ # Test/Generate 300 passwords
26
+ foreach ($attempt in (1 .. 300 )){
27
+ It " Should generate a password complex enough for AD ($attempt /300 attempt)" {
28
+ $n = 8 .. 32 | Get-Random
29
+ $RegEx = " (?=^.{8,32}$)((?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^.*"
30
+ (New-RandomPassword ($n )) -match $RegEx
31
+ }
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments