Create a Strong Random Password with VBScript

I had been using a simple script to create an alpha numeric password that was all lower case for quite some time. Recently though I decided to give the old password creation function an overhaul since the old password creation function was very weak.

This new function will create a new string that is alpha numeric, upper and lower case letters, and also valid type-able characters. I decided to filter out the quotation mark (“) because it can often time cause issues when you have to pass the password within scripts. It is replaced by the single quote when it happens to show up.

The really nice thing about this function is that you can create strings of variable length. So if you need a normal windows password you can pass a string of 15 characters. But if for some reason you need to create a string that is much longer, you can easily do that by just changing the value you pass to the function.

This particular function is a lifesaver when you use it to create user accounts with something like these functions I posted about earlier.

Function RndPassword(vLength)
  'This function will generate a random strong password of variable
  'This script is provided under the Creative Commons license located
  'at . It may not
  'be used for commercial purposes with out the expressed written consent
  For x=1 To vLength
    vChar = Int(89*Rnd) + 33
    If vChar = 34 Then 'this is quote character, replace it with a single quote
      vChar = 39
    End if

    RndPassword = RndPassword & Chr(vChar)

End Function


Leave a Comment