Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for pwgen.vbs

(view source code of pwgen.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim objCrypt, strArg, strPW
  4.  
  5. Const CAPICOM_ENCODE_ANY    = -1
  6. Const CAPICOM_ENCODE_BASE64 =  0
  7. Const CAPICOM_ENCODE_BINARY =  1
  8.  
  9. With WScript.Arguments
  10. 	If .Named.Count   <> 0 Then Syntax
  11. 	If .Unnamed.Count <> 1 Then Syntax
  12. 	strArg = .Unnamed(0)
  13. 	If Not IsNumeric( .Unnamed(0) ) Then Syntax
  14. 	If CInt( strArg ) <> CDbl( strArg ) Then Syntax
  15. End With
  16.  
  17. Set objCrypt = CreateObject( "CAPICOM.Utilities.1" )
  18.  
  19. strPW = Left( objCrypt.GetRandom( strArg, CAPICOM_ENCODE_ANY ), strArg )
  20.  
  21. Set objCrypt = Nothing
  22.  
  23. WScript.Echo strPW
  24.  
  25.  
  26. Sub Syntax
  27. 	Dim strMsg
  28. 	strMsg = vbCrLf _
  29. 	       & WScript.ScriptName & ",  Version 1.00" _
  30. 	       & vbCrLf _
  31. 	       & "Generate random complex passwords with a specified length" _
  32. 	       & vbCrLf & vbCrLf _
  33. 	       & "Usage:  " & UCase( WScript.ScriptName ) & "  length" _
  34. 	       & vbCrLf & vbCrLf _
  35. 	       & "Where:  ""length""  is an integer specifying the requested password length" _
  36. 	       & vbCrLf & vbCrLf _
  37. 	       & "Written by Rob van der Woude" _
  38. 	       & vbCrLf _
  39. 	       & "http://www.robvanderwoude.com"
  40. 	WScript.Echo strMsg
  41. 	WScript.Quit 1
  42. End Sub
  43.  

page last modified: 2024-04-16; loaded in 0.0057 seconds