Lee_Dailey

Passphrase/Password maker - v2

Dec 18th, 2020
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # save the old Verbose pref
  2. $OldVPref = $VerbosePreference
  3. # enable verbose output
  4. $VerbosePreference = 'Continue'
  5.  
  6. # enable newer web secure protocols
  7. [Net.ServicePointManager]::SecurityProtocol = 'tls12, tls11, tls'
  8.  
  9. $URL = 'https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt'
  10. $WordCount = 4
  11. $UpCaseCount = 4
  12. $NumberRange = 10..999
  13.  
  14. $SourceDir = $env:TEMP
  15. $SourceFile = 'EFF_Large_Word_List.txt'
  16. $FullSourceFile = Join-Path -Path $SourceDir -ChildPath $SourceFile
  17.  
  18. $SymbolChars = '!@#$%^&()_-{}[]<>'.ToCharArray()
  19.  
  20. # if the file is there, use it
  21. #    otherwise get from the URL and save it to the named file
  22. Write-Verbose 'Checking for local copy of word list ...'
  23. if (-not (Test-Path -Path $FullSourceFile))
  24.     {
  25.     Write-Verbose '    Local word list file NOT found - downloading a large-ish text file ...'
  26.     (Invoke-RestMethod -Uri $URL).Split("`n").Trim() |
  27.         Set-Content -LiteralPath $FullSourceFile
  28.     Write-Verbose '    Local word list file saved.'
  29.     }
  30.     else
  31.     {
  32.     Write-Verbose '    Local word list file found.'
  33.     }
  34.  
  35. $SourceWordList = Get-Content -Path $FullSourceFile
  36.  
  37. $WordList = Get-Random -InputObject $SourceWordList -Count $WordCount
  38. # each line = number<space>word, so take only the word
  39. $WordList = $WordList.ForEach({($_ -split '\s{1,}')[-1]})
  40. # title case each word
  41. $WordList = $WordList.ForEach({(Get-Culture).TextInfo.ToTitleCase($_)})
  42.  
  43. # merge with spaces to make a passphrase
  44. $PassPhrase = $WordList -join ' '
  45.  
  46. # merge the words into one lower case word
  47. $Password = (-join $WordList).ToLower()
  48.  
  49. # get $UpCaseCount indexes for up-casing random letters in $Password
  50. $ChangeIndexList = Get-Random -InputObject (0..($Password.Length - 1)) -Count $UpCaseCount
  51. foreach ($CIL_Item in $ChangeIndexList)
  52.     {
  53.     $UCLetter = ([string]$Password[$CIL_Item]).ToUpper()
  54.     $Password = $Password.Remove($CIL_Item,1).Insert($CIL_Item, $UCLetter)
  55.     }
  56.  
  57. $Password = -join (
  58.     $Password,
  59.     (Get-Random -InputObject $SymbolChars -Count 1),
  60.     (Get-Random -InputObject $NumberRange -Count 1)
  61.     )
  62.  
  63. ''
  64. 'Password    = {0}' -f $Password
  65. 'Passphrase  = {0}' -f $PassPhrase
  66.  
  67. # restore previous VPref
  68. $VerbosePreference = $OldVPref
  69.  
Add Comment
Please, Sign In to add comment