Problem with random password

I am using the code below to create a 10 digit random string.
After the string is generated it is encrypted and saved in the database, the encryption doesn't modify the string content other than encrypting it, then I am testing and displaying the string decrypted on the page and I find that most times the string is LESS than 10 characters long.

Is there something off with the script below or maybe one of the characters being used may be causing the string to change size ?
I don't have access to the encryption code at this time so perhaps we can figure it out with the script below:

IT SHOULD ALWAYS BE 10 digits long.

<%
function RandomString()

    Randomize()

    dim CharacterSetArray
   CharacterSetArray = Array(_
         Array(4, "abcdefghijklmnopqrstuvwxyz"), _
         Array(2, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"), _
         Array(2, "!@#%&*+"), _
         Array(2, "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

LVL 1
AleksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aikimarkCommented:
Since this is a security-related issue, you should know about weaknesses with the VB random number functions.

An Examination of Visual Basic's Random Number Generation: http://rdsrc.us/fErAk9
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
Yes thank you, but for now the question is different.
0
aikimarkCommented:
I don't see anything wrong with your code.  It should always produce a character string of length 10 that contains characters from the groups in the amounts specified by the count values in each group.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

AleksAuthor Commented:
So maybe the encrypt function breaks somewhere with one of those special characters. Any of them that you think could be an issue ?
0
Dave BaldwinFixer of ProblemsCommented:
Can you show us the simple example of how you are using it and some input strings that give a result you aren't expecting?
0
aikimarkCommented:
All the characters could cause problems, depending on the code that's processing the string.
0
AleksAuthor Commented:
I am changing the encryption altogether. If I have issues with the new one Ill repost then.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.