Skip to content

Commit

Permalink
Merge pull request #20 from agreenbhm/patch-1
Browse files Browse the repository at this point in the history
Added token generation compatibility for Linux & MacOS
  • Loading branch information
UpperM authored Dec 1, 2023
2 parents b70e349 + 4f8ae95 commit 8de6b6f
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions PSGuacamole/Public/APIConnection/New-GuacToken.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,22 @@ Function New-GuacToken()
if ($Null -eq $Password -or $Password.Length -eq 0)
{
$SecurePassword = Read-Host "Enter password" -AsSecureString

# Decode SecureString to Plain text for Guacamole (https://www.powershelladmin.com/wiki/Powershell_prompt_for_password_convert_securestring_to_plain_text)
# Create a "password pointer"
$PasswordPointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)

# Get the plain text version of the password
$Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto($PasswordPointer)

# Free the pointer
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($PasswordPointer)
# If running on Windows
if ($IsWindows)
{
# Decode SecureString to Plain text for Guacamole (https://www.powershelladmin.com/wiki/Powershell_prompt_for_password_convert_securestring_to_plain_text)
# Create a "password pointer"
$PasswordPointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)

# Get the plain text version of the password
$Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto($PasswordPointer)

# Free the pointer
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($PasswordPointer)
# If running on Linux of MacOS
} else {
$Password = ConvertFrom-SecureString -SecureString $SecurePassword -AsPlaintext
}
}

$Body = @{
Expand Down

0 comments on commit 8de6b6f

Please sign in to comment.