PDA

View Full Version : Solved: Separate generated password with dashes



av8tordude
07-23-2011, 12:08 PM
This code generates a random generated password. Can someone assist with editing this code to increase the characters generated from 10 characters to 16 characters. Also separate each 4th character with a dash.

ex.

INIw-yOH9-Aewy-OH93

Public Function rndStr(ByRef StrLength As Long) As String
Dim b() As Byte, keyArr() As Byte
Dim i As Long
Let keyArr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
ReDim b(1 To StrLength * 2)
For i = 1 To StrLength * 2 Step 2
Let b(i) = keyArr(Int(((UBound(keyArr) + 1) \ 2) * Rnd + 1) * 2 - 2)
Next
Let rndStr = b
End Function

p45cal
07-23-2011, 02:16 PM
to increase the characters generated from 10 characters to 16 characters
Change the 10 argument when you call it, to 16.

separate each 4th character with a dash
Public Function RndStr(ByRef StrLength As Long) As String
Dim b() As Byte, keyArr() As Byte, TempStr1 As String, TempStr2 As String
Dim i As Long
Let keyArr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
ReDim b(1 To StrLength * 2)
For i = 1 To StrLength * 2 Step 2
Let b(i) = keyArr(Int(((UBound(keyArr) + 1) \ 2) * Rnd + 1) * 2 - 2)
Next
Let TempStr1 = b
For i = 1 To StrLength Step 4
TempStr2 = TempStr2 & Mid(TempStr1, i, 4) & "-"
Next i
TempStr2 = Left(TempStr2, Len(TempStr2) - 1)
RndStr = TempStr2
End Function

av8tordude
07-24-2011, 09:23 AM
Thank you p45cal. Works great!:friends: