• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

create random string of characters

hello experts

i need to generate a string of random characters that will be a password for users signing up to my site. after logging in with the random password, they will be forced to change it. I'm still new when it comes to asp, but I know there is a Randomize() function that'll return random numbers. I imagine I'll have to create a character set, then randomly pick different spots within that character set to get a random string of letters/numbers, but I'm not sure how to go about that.

TIA
0
c l
Asked:
c l
1 Solution
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
you're on the right track, you do want a char set to start with and randomly grab different positions in that string to get the random password. Here's a function I've used successfully in my own sites that do exactly what you're looking for. just create a variable and store the results of the function in that variable. any questions feel free to ask.

function RandomString()

    Randomize()

    dim CharacterSetArray
    CharacterSetArray = Array(_
        Array(7, "abcdefghijklmnopqrstuvwxyz"), _
        Array(1, "0123456789") _
    )

    dim i
    dim j
    dim Count
    dim Chars
    dim Index
    dim Temp

    for i = 0 to UBound(CharacterSetArray)

        Count = CharacterSetArray(i)(0)
        Chars = CharacterSetArray(i)(1)

        for j = 1 to Count

            Index = Int(Rnd() * Len(Chars)) + 1
            Temp = Temp & Mid(Chars, Index, 1)

        next

    next

    dim TempCopy

    do until Len(Temp) = 0

        Index = Int(Rnd() * Len(Temp)) + 1
        TempCopy = TempCopy & Mid(Temp, Index, 1)
        Temp = Mid(Temp, 1, Index - 1) & Mid(Temp, Index + 1)

    loop

    RandomString = TempCopy

end function

Open in new window

0
 
c lAuthor Commented:
thank you, works perfectly!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now