document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. # Code Snippet from aperturescience.su
  2. Function Get-BCryptHash
  3. {
  4. <#
  5. .SYNOPSIS
  6. Gets a hash the string provided using either salt or workfactor provided.
  7.  
  8. .DESCRIPTION
  9. The cmdlet will return a hash of the string provided to it, you can optionally specify a salt to be used, otherwise a salt will be generated on the fly. A workfactor can be specified for the salt generated on the fly.
  10.  
  11. You cannot specify a salt and a workfactor, only one can be specified at any one time. If both are specified an error will be throw.
  12.  
  13. .PARAMETER InputString
  14. [Pipeline] String to be hashed
  15.  
  16. .PARAMETER WorkFactor
  17. [Optional] Workfactor for salt if generating one on the fly
  18.  
  19. .PARAMETER Salt
  20. [Optional] Salt to be used during the hashing process
  21.  
  22. .INPUTS
  23. Accepts strings to be hashed on pipeline (InputString)
  24.  
  25. .OUTPUTS
  26. Hashes of input string
  27.  
  28. .EXAMPLE
  29. Get-BCryptStringHash "MyPassword"
  30. Returns the bcrypt has of the input string "MyPassword" with a random salt, this will produce a different has every time you run this!
  31.  
  32. .EXAMPLE
  33. @("Password1", "Password2", "Password3") | Get-BCryptStringHash -Salt $MyBCryptSalt
  34.  
  35. .NOTES
  36. NAME: Get-BCryptStringHash
  37. LASTEDIT: 2012-11-17 11:15:00
  38. KEYWORDS: bcrypt, hash, password
  39.  
  40. .LINK
  41. http://bcrypt.codeplex.com/
  42.  
  43. .LINK
  44. http://aperturescience.su/
  45. #>
  46. [CMDLetBinding()]
  47. param
  48. (
  49.     [Parameter(mandatory=$true, valuefrompipeline=$true)] [String] $InputString,
  50.     [Int] $WorkFactor,
  51.     [String] $Salt
  52. )
  53.  
  54. Begin
  55. {
  56.     #Test if the user specified both workfactor and salt, if they did throw an error
  57.     if ($WorkFactor -and $Salt)
  58.     {
  59.         throw "You cannot specify both a WorkFactor and a Salt, please specify one or the other"
  60.     }
  61. }
  62.  
  63. Process
  64. {
  65.     #if workfactor was specified, then we call that function, otherwise if the salt was spcified,
  66.     #   then use that function, otherwise just the plain inputstring function
  67.     if ($WorkFactor)
  68.     {
  69.         return [bcrypt.net.bcrypt]::hashpassword($InputString, $WorkFactor)
  70.     }
  71.     elseif ($Salt)
  72.     {
  73.         return [bcrypt.net.bcrypt]::hashpassword($InputString, $Salt)
  74.     }
  75.     else
  76.     {
  77.         return [bcrypt.net.bcrypt]::hashpassword($InputString)
  78.     }
  79. }
  80.  
  81. }
  82. # Code Snippet from aperturescience.su
');