'---------------------------------------------------------------------------------------
' Procedure : GetPWDCharacters
' Author    : Patrick Wood  http://gainingaccess.net
' Date      : 8/10/2011, Modified 6/3/2016
' Purpose   : Get Random Characters (These are also safe to use for ODBC Passwords).
' Arguments : lngCount is the number of characters you want returned.
' Example   : strPassword = GetPWDCharacters(15) - Returns a string of 15 characters.
'---------------------------------------------------------------------------------------
Function GetPWDCharacters(lngCount As Long) As String

    Dim i As Long
    Dim j As Long
    Dim arrCharacters As Variant
    Dim strCharacters As String

    ' Build an array of Characters including all letters and numbers and safe special characters.
    ' This procedure omits these ODBC characters which Microsoft advises us
    ' not to use in Login Names and Passwords: []{}(),;?*!@.
    arrCharacters = Array( _
        "o", "S", "v", "2", "y", "Z", "I", "%", "t", "x", "6", "W", "q", "_", "j", "u", _
        "8", "k", "L", ">", "m", "C", "R", "/", "P", "9", "d", "h", "^", "w", "B", "f", _
        "+", "Q", "i", "E", "&", "a", "X", "U", "=", "g", "b", "F", "$", "O", "Y", "J", _
        "3", "0", "K", "p", "~", "s", "M", "4", "H", "l", "#", "D", "G", "N", "\", "V", _
        "c", "z", "1", "5", "T", "e", "7", "n", "<", "A", "r")

    ' Loop the number of times entered.
    For i = 1 To lngCount
	
        ' Get a random number to use with the array. Thanks to Philipp Stiefel for reminding me to use "Randomize" here.
        Randomize
        j = Int((UBound(arrCharacters) - LBound(arrCharacters) + 1) * Rnd + LBound(arrCharacters))

        ' Get a Random character and add it to the string.
        strCharacters = strCharacters & arrCharacters(j)
    Next i

    GetPWDCharacters = strCharacters

End Function