Skip to content

Commit

Permalink
Restores Windows PowerShell 5.1 compatibility.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rhymeswithmogul committed Nov 3, 2024
1 parent 7d1b62b commit e207932
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
5 changes: 4 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
12 changes: 9 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.)

Expand Down
8 changes: 3 additions & 5 deletions PSPasswordGenerator.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion src/PSPasswordGenerator.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit e207932

Please sign in to comment.