Skip to content

Commit

Permalink
Disallow dollar char can be a useful switch for XM Cloud project and … (
Browse files Browse the repository at this point in the history
#47)

* Disallow dollar char can be a useful switch for XM Cloud project and other Docker projects where random string with $ throws up.ps1 error

* fixed rookie error
  • Loading branch information
navancommits authored Apr 24, 2023
1 parent cd424f2 commit fd5b454
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions powershell/src/Public/Get-SitecoreRandomString.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Set-StrictMode -Version Latest
Ensures the returned string contains at least one of each of the allowed character types.
.PARAMETER DisallowSpecial
Prevent the special characters ~!@#$%^&*_-+=`|(){}[]:;<>.?/
.PARAMETER DisallowDollar
Prevent just $ symbol
.PARAMETER DisallowCaps
Prevent capital letters from appearing in the generated sting.
.PARAMETER DisallowLower
Expand All @@ -26,7 +28,7 @@ Set-StrictMode -Version Latest
.EXAMPLE
PS C:\> Get-SitecoreRandomString -Length 10
.EXAMPLE
PS C:\> Get-SitecoreRandomString -Length 10 -EnforceComplexity -DisallowSpecial
PS C:\> Get-SitecoreRandomString -Length 10 -EnforceComplexity -DisallowDollar
#>
function Get-SitecoreRandomString
{
Expand Down Expand Up @@ -54,7 +56,11 @@ function Get-SitecoreRandomString

[Parameter(ParameterSetName = 'custom', Position = 5)]
[switch]
$DisallowNumbers
$DisallowNumbers,

[Parameter(ParameterSetName = 'custom', Position = 6)]
[switch]
$DisallowDollar
)

$complexity = 0
Expand All @@ -65,6 +71,7 @@ function Get-SitecoreRandomString
$DisallowLower = $false
$DisallowNumbers = $false
$DisallowSpecial = $false
$DisallowDollar = $false
}

if (!$DisallowCaps) {
Expand All @@ -83,7 +90,13 @@ function Get-SitecoreRandomString
}

if (!$DisallowSpecial) {
$charset += ('~','!','@','#','$','%','^','&','*','_','-','+','=','`','|','\','(',')','{','}','[',']',':',';','<','>','.','?','/')
if (!$DisallowDollar) {
$charset += ('~','!','@','#','$','%','^','&','*','_','-','+','=','`','|','\','(',')','{','}','[',']',':',';','<','>','.','?','/')
}
else
{
$charset += ('~','!','@','#','%','^','&','*','_','-','+','=','`','|','\','(',')','{','}','[',']',':',';','<','>','.','?','/')
}
$complexity = $complexity + 1
}

Expand Down

0 comments on commit fd5b454

Please sign in to comment.