Consulting

Results 1 to 3 of 3

Thread: Solved: Separate generated password with dashes

  1. #1

    Solved: Separate generated password with dashes

    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

    [vba]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[/vba]

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,874
    Quote Originally Posted by av8tordude
    to increase the characters generated from 10 characters to 16 characters
    Change the 10 argument when you call it, to 16.
    Quote Originally Posted by av8tordude
    separate each 4th character with a dash
    [VBA]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
    [/VBA]
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Thank you p45cal. Works great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •