COM object Random Password

Results 1 to 2 of 2

Thread: COM object Random Password

  1. #1
    Join Date
    Dec 1969

    Default COM object Random Password

    I have developed a ActiveX dll in VB 6 to generate a random password for new registrants on our intranet. <BR><BR>MY PROBLEM: The passwords are always generated in a pattern, despite what looks to me like a valid use of the random (Rnd()) function. <BR><BR>This looks like it should work to me!! Please take a look and tell me what I&#039m overlooking. I have used the Rnd() function in the past and it has always worked well. This works exactly the same in VB and Access 97/2000. <BR><BR>Here goes the code:<BR>(Please excuse the Reddick coding notations.)<BR><BR>***********START*************** *****<BR><BR>Public Function GenAlphaNumPass(lngLength As Long)<BR>On Error GoTo failure<BR><BR> Dim strRet As String<BR> Dim strAlpha As String<BR> Dim strNum As String<BR> Dim c As Integer<BR> Dim blnAlphaNum As Boolean<BR> Dim intPos As Integer<BR> Dim strChar As String<BR> <BR> strAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"<BR> strNum = "1234567890"<BR> For c = 1 To lngLength<BR><BR> blnAlphaNum = Int((Rnd) + 0.5)<BR> <BR> If blnAlphaNum = 0 Then &#039USE AN ALPHA CHAR.<BR> intPos = Int((26 * Rnd) + 1)<BR> strChar = Mid$(strAlpha, intPos, 1)<BR> Else &#039USE A NUMERIC CHAR.<BR> intPos = Int((10 * Rnd) + 1)<BR> strChar = Mid$(strNum, intPos, 1)<BR> End If<BR> strRet = strRet & strChar<BR> Next c<BR> <BR> GenAlphaNumPass = strRet<BR><BR>exitroutine:<BR> Exit Function<BR>failure:<BR> Msgbox err & " " & err.DESCRIPTION<BR> Resume exitroutine<BR>End Function<BR><BR>**********END*****************<BR> <BR>Running it multiple times in a row(passing 14 as length), the returns that it gives me<BR>(in order) are:<BR><BR>63UT8K8Z148PH7<BR>H9030NZ12UBJY5<BR>EQ K43PL34X7C79<BR>O565KBZKMMQ274<BR>UT9FCDN61RJS6T<B R>MFC21H8RCI3MIM<BR>W841527DF2I059<BR>84K2O6NQR4HN PW<BR>E88VYB4DES6M8X<BR><BR>I&#039m not a mathematician by any means. Why is this function holding this pattern?<BR><BR>Thanks, <BR><BR>Tom Oakes<BR><BR><BR><BR><BR><BR><BR> <BR>

  2. #2
    Steve Cimino Guest

    Default RE: COM object Random Password

    You need to call the sub Randomize first. Check the docs on it. Basically, if you just do this:<BR><BR>Randomize<BR>i = Int((Rnd * 99) + 1) &#039Pick a number between 1 and 100<BR><BR>will give you a different set of numbers. Using Randomize without passing it a number defaults to your system clock (rather unique each time).

Posting Permissions

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