Issue when using -AsSecureString cmdlet

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of Ali Hassan Ali Hassan 4 weeks ago.

  • Author
    Posts
  • #73975
    Profile photo of Ali Hassan
    Ali Hassan
    Participant

    Hi Guys,

    I am facing a very odd issue, I have a script which prompt for the user password and checks if the password is complex or not depending on some criteria I have set. Below is the script block that i am using

     $username = read-host "Please enter your username"
     $password = read-host "Please enter the password you want to test" -AsSecureString 
    

    So i enter the password as –> powershell.com (just to test)

    As per the criteria I get there is an upper case in the password.

    But when I remove the -asSecureString parameter, and enter the same password. it seems to pass the check properly.

    Does using -AsSecureString change anything while storing the password?

  • #73976
    Profile photo of Ali Hassan
    Ali Hassan
    Participant

    Found a way!

    $password = read-host -assecurestring
    $decodedpassword =[System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)) 
    

    This seems to work alright...

    -A

You must be logged in to reply to this topic.