create random string of characters

Posted on 2014-08-07
Last Modified: 2014-08-07
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.

Question by:c l
    LVL 32

    Accepted Solution

    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()
        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)
        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)
        RandomString = TempCopy
    end function

    Open in new window

    LVL 2

    Author Comment

    by:c l
    thank you, works perfectly!

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
    I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
    This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now