From e2079324e9dabf9ec9645fa4e157fcf007202140 Mon Sep 17 00:00:00 2001 From: Colin Cogle Date: Sun, 3 Nov 2024 11:10:35 -0500 Subject: [PATCH] Restores Windows PowerShell 5.1 compatibility. Versions 3.0.0 to 3.1.0 (inclusive) of this module contained a bug that prevented it from working correctly on Windows PowerShell 5.1. The call to `ConvertFrom-SecureString` used the parameter `-AsPlainText`, which does not exist before PowerShell 7.0. This commit fixes that by checking to see if `ConvertFrom-SecureString` supports the `-AsPlainText` parameter. If so, it is called with it, and if not, it's called without it. Fixes #7 --- ChangeLog.md | 5 ++++- NEWS.md | 12 +++++++++--- PSPasswordGenerator.psd1 | 8 +++----- src/PSPasswordGenerator.psm1 | 8 +++++++- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 9bcf329..b7a88b8 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,9 @@ # PSPasswordGenerator change log -## Version 3.1.0 (coming soon) +## Version 3.2.0 (not yet released) +- Fixes a bug where the `-AsPlainText` parameter would fail on Windows PowerShell 5.1 because `ConvertFrom-SecureString -AsPlainText` doesn't exist on that version. Thanks to [GitHub user @jrbilodeau](https://github.com/jrbilodeau) for reporting [this issue](https://github.com/rhymeswithmogul/PSPasswordGenerator/issues/7). + +## Version 3.1.0 (February 13, 2024) - This version is more secure, as the generated password is now built in memory as a `[SecureString]`, and only converted from one when this cmdlet is run with `-AsPlainText`. - Added a new `-ExcludeCharacters` parameter which does as it says; generated passwords will not include those characters. Thanks to [GitHub user @wwc-trevor](https://github.com/wwc-trevor) for [the great idea](https://github.com/rhymeswithmogul/PSPasswordGenerator/issues/4) and for testing my work. - Packaging improvements. diff --git a/NEWS.md b/NEWS.md index ed62cfe..fefe808 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,13 +1,19 @@ # PSPasswordGenerator History of user-visible changes. -Last update: 2024-02-01 +Last update: 2024-11-03 -## PSPasswordGenerator version 3.0.1, in development +## PSPasswordGenerator version 3.2.0, in development +- Fixes a bug where the `-AsPlainText` parameter would fail on Windows PowerShell 5.1 because `ConvertFrom-SecureString -AsPlainText` doesn't exist on that version. Thanks to [GitHub user @jrbilodeau](https://github.com/jrbilodeau) for reporting [this issue](https://github.com/rhymeswithmogul/PSPasswordGenerator/issues/7). + +## PSPasswordGenerator version 3.1.0, released 2024-02-13 +- This version is more secure, as the generated password is now built in memory as a `[SecureString]`, and only converted from one when this cmdlet is run with `-AsPlainText`. +- Added a new `-ExcludeCharacters` parameter which does as it says; generated passwords will not include those characters. Thanks to [GitHub user @wwc-trevor](https://github.com/wwc-trevor) for [the great idea](https://github.com/rhymeswithmogul/PSPasswordGenerator/issues/4) and for testing my work. + +## PSPasswordGenerator version 3.0.1 This version builds the password in-memory as a `[SecureString]`, which means it is never stored insecurely. In addition, I've added a new `-ExcludeCharacters`` parameter which does as it says; generated passwords will not include those characters. Thanks to [GitHub user @wwc-trevor](https://github.com/wwc-trevor) for [the great idea](https://github.com/rhymeswithmogul/PSPasswordGenerator/issues/4) and for testing my work. - ## PSPasswordGenerator version 3.0.0, released 3/17/2022 Not dead yet! In this version, the cmdlet's verb has been changed. It is now called `Get-RandomPassword` (but `New-RandomPassword` still works.) diff --git a/PSPasswordGenerator.psd1 b/PSPasswordGenerator.psd1 index 2f6a992..ed6b0ca 100644 --- a/PSPasswordGenerator.psd1 +++ b/PSPasswordGenerator.psd1 @@ -22,7 +22,7 @@ RootModule = 'src/PSPasswordGenerator.psm1' # Version number of this module. -ModuleVersion = '3.1.0' +ModuleVersion = '3.2.0' # Supported PSEditions CompatiblePSEditions = @('Desktop', 'Core') @@ -91,15 +91,13 @@ PrivateData = @{ IconUri = 'https://raw.githubusercontent.com/rhymeswithmogul/PSPasswordGenerator/main/icon/PSPasswordGenerator.png' # ReleaseNotes of this module - ReleaseNotes = '- Strings are now generated securely on supported platforms. -- Added a new ExcludeCharacters parameter which does as it says; generated passwords will not include those characters. -- Packaging improvements.' + ReleaseNotes = 'Fixes a bug preventing this from running on Windows PowerShell 5.1.' # Flag to indicate whether the module requires explicit user acceptance for install/update/save RequireLicenseAcceptance = $false # Beta? - #Prerelease = 'git' + Prerelease = 'git' } # End of PSData hashtable diff --git a/src/PSPasswordGenerator.psm1 b/src/PSPasswordGenerator.psm1 index e55469c..d281fd1 100644 --- a/src/PSPasswordGenerator.psm1 +++ b/src/PSPasswordGenerator.psm1 @@ -156,7 +156,13 @@ Function Get-RandomPassword } If ($AsPlainText) { - Return (ConvertFrom-SecureString $ret -AsPlainText) + If ((Get-Command 'ConvertFrom-SecureString').Parameters.ContainsKey('AsPlainText')) { + Return (ConvertFrom-SecureString $ret -AsPlainText) + } + Else { + Return (ConvertFrom-SecureString $ret) + + } } Else { Return $ret }