Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - comparing secure strings...

Reply
 
Old 03-12-2008   #1 (permalink)
Ben Christian


 
 

comparing secure strings...

i want to compare 2 user inputted secure strings

$strA = read-host -assecurestring "Enter String"
$strB = read-host -assecurestring "Re-Enter String"

if ($strA -eq $strB) { write-host "Strings Match" }
else { write-host "Strings do NOT match" }

but...the problem is that it seems to always return false =(

any suggestions?

My System SpecsSystem Spec
Old 03-13-2008   #2 (permalink)
Shay Levi


 
 

Re: comparing secure strings...



You can convert the secure strings to plain text and do the comparison:


$strA = read-host -assecurestring "Enter String"
$strB = read-host -assecurestring "Re-Enter String"

$tmpA = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($strA))
$tmpB = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($strB))

$tmpA -eq $tmpB



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> i want to compare 2 user inputted secure strings
>
> $strA = read-host -assecurestring "Enter String"
> $strB = read-host -assecurestring "Re-Enter String"
> if ($strA -eq $strB) { write-host "Strings Match" } else { write-host
> "Strings do NOT match" }
>
> but...the problem is that it seems to always return false =(
>
> any suggestions?
>

My System SpecsSystem Spec
Old 04-02-2008   #3 (permalink)
David Marvin


 
 

RE: comparing secure strings...

I have the same question. I don't want to convert the SecureString back into
text as this defeats the purpose of the SecureString. Can this be
accomplished without using ConvertFrom-SecureString ?
My System SpecsSystem Spec
Old 04-02-2008   #4 (permalink)
Oisin (x0n) Grehan [MVP]


 
 

Re: comparing secure strings...

On Apr 2, 4:04*pm, David Marvin
<DavidMar...@xxxxxx> wrote:
Quote:

> I have the same question. *I don't want to convert the SecureString backinto
> text as this defeats the purpose of the SecureString. *Can this be
> accomplished without using ConvertFrom-SecureString ?
If you think about it a little bit more, being able to compare secure-
strings without decrypting them also defeats the purpose ;-)

function crack-password ($secureString) {

$words = get-content dictionary.txt

foreach ($word in $words) {

$crypted = ConvertTo-SecureString $word

if ($crypted -eq $secureString) {
write-host "Password is $word"
break;
}
}
}

Of course, this imaginary function will NOT work.

Hope this clears things up, :-)

- Oisin

PowerShell MVP
http://www.nivot.org/
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Trouble comparing strings PowerShell
Comparing dates with If PowerShell
Comparing strings - is it a bug? PowerShell
Comparing filenames to strings PowerShell
secure and non secure items message Vista security


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46