Advertisement
Lee_Dailey

Pass_Phrase-or-Word_Generator

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