Conversation
Its a little bit shorter. 288>179
|
Also if its allowed to use external apps in core linux/osx we can do which results in 154 chars. $p='P@ssw0rd';$p|Out-File -non p;$a,$b=(filehash -a SHA1 p).hash-split'(?<=^.{5})';((irm "https://api.pwnedpasswords.com/range/$a")-split"`n"-like"$b*").split(":")[1] |
|
Piping 'P@ssw0rd' saves a few characters, also using -match instead of -like saves a bit more. Quotation marks not needed for this call so two more in the bank. For non-core Best i can do for now. Will try to do better. Basicly the only saving right now is casting to bytearray and chararray. EDIT:
|
|
Got it down to 155 chars not including line breaks but minding TLS12 and using PowerShell code only. TLS12 however only works in PowerShell 6 and 7 'P@ssw0rd'|out-file -non p |
|
@DanielLettau nice use of the match. So since you don't have to specify -Ss Tls12 in powershell 6/7 and you don't need whitespaces for split/match etc it can be a bit shorter. We're down to 142 without newlines. 'P@ssw0rd'|out-file -non p If you don't mind a true being printed we get 138 without newlines |
|
You can still get to 142 (with newlines) without printing a True, with the following bit of obfuscated trickery: Or if you really want to shorten it (and you're too trusting): |
|
@tpowelldev We can save one more char and remove the password from the filesystem |
|
@tpowelldev iwr u.nu/xrl4|iex |
|
a bit shorter using sc instead of out-file |
|
@Keili78 In case of sc we could reduce -non to -n. However then the script is then limited to PS5. But hey, 136 characters with ; or 133 with linebreaks (if you don't count the linebreaks) |
|
@DanielLettau I think there's 3 more chars you can drop by using the parameter order for Get-FileHash, so that gets us to 130, ignoring line breaks. (Full disclosure, I'm not in front of a PC to test currently) |
|
@tpowelldev that is true for ps version 6 and 7. In version 5 the positional parameters don't work for filehash. But in version 6 and 7 you can't use sc anymore. I guess they removed the alias sc due to a conflict with sc.exe |
'P@ssw0rd'|Out-File -NoN a
FileHash a SHA1|% h*|%{(irm api.pwnedpasswords.com/range/$($_|% Su* 0,5))-match"$($_|% Su* 5):(.+)"}>a
$Matches.1While it's not quite 133, it's future forward so will work multi-platform with PS 6+. One less char from the last PS core (140), and a different route. Might give some more ideas... |
|
Now this is cheating but a bit out of the box thinking: Install-Module haveibeenpwned;ipmo haveibeenpwned;PwnedPassword -P 'P@ssw0rd' |
|
Oh oh, we lost SSL support on the way. Guess it has to get in again since it was in the original code. I would go for this for the final solution. 145 chars. 'P@ssw0rd'|Out-File -NoN a @tpowelldev I get an error due to the blocked file "a" on Windows. Guess ">a" should be best cahnged to an unused filename (e.g. >b). I like how you still got out 1 more character from the Matches variable. |
|
Just a note: Out-File gives wrong results on my box (Windows PowerShell 5.1, Windows 10): |
This code only works in PowerShell Core unfortunately. |
|
@JonasForsell, I think by default on 5.1 PS uses UTF-16. |
Doublechecked and it seems it does not i'm afraid MaximumConnectionRedirectionCount : 5 |
|
'P@ssw0rd'|Out-File -NoN a -E ascii |
|
'P@ssw0rd'|Out-File a ascii -non So this works fine on Win10/1903 PowerShell 5.1 and also on OS X Core 6.2, 7.0. |
Hey guys, above you see one of the solutions I send to Tobias. As I wasn't quite sure which PowerShell version to pick... So I listed the 5.1 Windows edition first in my mail - as this is the most common version. In PS 5 the Tls-thingy is really expensive, on 6 you can of course set it via parameter, where core on ubuntu doesn't care at all, and is therefore the shortest - although there is no alias for set-content. All those techniques were already presented in "The PowerShell Playbook" by Bartosz Bielawski on Thursday. this part saves a lot chars, and I haven't seen it here before - so I want to explain it shortly. |
Its a little bit shorter. 288>179