@@ -13,14 +13,6 @@ function Invoke-ExecPasswordConfig {
1313 $Table = Get-CIPPTable - TableName Settings
1414 $PasswordSettings = Get-CIPPAzDataTableEntity @Table - Filter " PartitionKey eq 'settings' and RowKey eq 'settings'"
1515
16- # Helper functions for consistent data conversion
17- function ConvertTo-Bool ($raw ) {
18- if ($null -eq $raw ) { return $false }
19- $stringValue = " $raw "
20- return ($stringValue -eq ' true' -or $stringValue -eq ' 1' -or $stringValue -eq ' yes' )
21- }
22-
23-
2416 $results = try {
2517 if ($Request.Query.List ) {
2618 if (-not $PasswordSettings ) {
@@ -50,16 +42,16 @@ function Invoke-ExecPasswordConfig {
5042 $resolvedConfig = @ {
5143 passwordType = $storedType
5244 charCount = if ($PasswordSettings.charCount -and [int ]::TryParse(" $ ( $PasswordSettings.charCount ) " , [ref ]$null )) { [int ]$PasswordSettings.charCount } else { 14 }
53- includeUppercase = if ($null -ne $PasswordSettings.includeUppercase ) { ConvertTo-Bool $PasswordSettings.includeUppercase } else { $true }
54- includeLowercase = if ($null -ne $PasswordSettings.includeLowercase ) { ConvertTo-Bool $PasswordSettings.includeLowercase } else { $true }
55- includeDigits = if ($null -ne $PasswordSettings.includeDigits ) { ConvertTo-Bool $PasswordSettings.includeDigits } else { $true }
56- includeSpecialChars = if ($null -ne $PasswordSettings.includeSpecialChars ) { ConvertTo-Bool $PasswordSettings.includeSpecialChars } else { $true }
45+ includeUppercase = if ($null -ne $PasswordSettings.includeUppercase ) { [ bool ] $PasswordSettings.includeUppercase } else { $true }
46+ includeLowercase = if ($null -ne $PasswordSettings.includeLowercase ) { [ bool ] $PasswordSettings.includeLowercase } else { $true }
47+ includeDigits = if ($null -ne $PasswordSettings.includeDigits ) { [ bool ] $PasswordSettings.includeDigits } else { $true }
48+ includeSpecialChars = if ($null -ne $PasswordSettings.includeSpecialChars ) { [ bool ] $PasswordSettings.includeSpecialChars } else { $true }
5749 specialCharSet = if ($PasswordSettings.specialCharSet ) { $PasswordSettings.specialCharSet } else { ' $%&*#' }
5850 wordCount = if ($PasswordSettings.wordCount -and [int ]::TryParse(" $ ( $PasswordSettings.wordCount ) " , [ref ]$null )) { [int ]$PasswordSettings.wordCount } else { 4 }
5951 separator = if ($null -ne $PasswordSettings.separator ) { $PasswordSettings.separator } else { ' -' }
60- capitalizeWords = if ($null -ne $PasswordSettings.capitalizeWords ) { ConvertTo-Bool $PasswordSettings.capitalizeWords } else { $false }
61- appendNumber = if ($null -ne $PasswordSettings.appendNumber ) { ConvertTo-Bool $PasswordSettings.appendNumber } else { $false }
62- appendSpecialChar = if ($null -ne $PasswordSettings.appendSpecialChar ) { ConvertTo-Bool $PasswordSettings.appendSpecialChar } else { $false }
52+ capitalizeWords = if ($null -ne $PasswordSettings.capitalizeWords ) { [ bool ] $PasswordSettings.capitalizeWords } else { $false }
53+ appendNumber = if ($null -ne $PasswordSettings.appendNumber ) { [ bool ] $PasswordSettings.appendNumber } else { $false }
54+ appendSpecialChar = if ($null -ne $PasswordSettings.appendSpecialChar ) { [ bool ] $PasswordSettings.appendSpecialChar } else { $false }
6355 }
6456
6557 # Persist migrated config so legacy type is upgraded in storage
@@ -100,13 +92,13 @@ function Invoke-ExecPasswordConfig {
10092 throw ' Please select a valid password type (Classic or Passphrase)'
10193 }
10294
103- $includeUppercase = ConvertTo-Bool $Request.Body.includeUppercase
104- $includeLowercase = ConvertTo-Bool $Request.Body.includeLowercase
105- $includeDigits = ConvertTo-Bool $Request.Body.includeDigits
106- $includeSpecialChars = ConvertTo-Bool $Request.Body.includeSpecialChars
107- $capitalizeWords = ConvertTo-Bool $Request.Body.capitalizeWords
108- $appendNumber = ConvertTo-Bool $Request.Body.appendNumber
109- $appendSpecialChar = ConvertTo-Bool $Request.Body.appendSpecialChar
95+ $includeUppercase = [ bool ] $Request.Body.includeUppercase
96+ $includeLowercase = [ bool ] $Request.Body.includeLowercase
97+ $includeDigits = [ bool ] $Request.Body.includeDigits
98+ $includeSpecialChars = [ bool ] $Request.Body.includeSpecialChars
99+ $capitalizeWords = [ bool ] $Request.Body.capitalizeWords
100+ $appendNumber = [ bool ] $Request.Body.appendNumber
101+ $appendSpecialChar = [ bool ] $Request.Body.appendSpecialChar
110102
111103 # Char count validation (classic only)
112104 $charCount = 0
@@ -129,9 +121,9 @@ function Invoke-ExecPasswordConfig {
129121 if (-not [int ]::TryParse(" $ ( $Request.Body.wordCount ) " , [ref ]$wordCount )) {
130122 $StatusCode = [HttpStatusCode ]::BadRequest
131123 throw ' Word count must be a valid number'
132- } elseif ($wordCount -lt 2 -or $wordCount -gt 10 ) {
124+ } elseif ($wordCount -lt 3 -or $wordCount -gt 10 ) {
133125 $StatusCode = [HttpStatusCode ]::BadRequest
134- throw ' Word count must be between 2 and 10 words'
126+ throw ' Word count must be between 3 and 10 words'
135127 }
136128 } else {
137129 if ([int ]::TryParse(" $ ( $Request.Body.wordCount ) " , [ref ]$wordCount )) { } else { $wordCount = 4 }
0 commit comments