Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generate same password in the same second
Message
De
11/11/2008 13:57:55
 
 
À
11/11/2008 11:17:42
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01360833
Message ID:
01361144
Vues:
13
>>I wonder
>>(1) Why do you still have loRnd around - it is non-static
>>(2) Why do you still use it ? ( lnNext = loRnd.Next(100) )
>>(3) Why the sleep() ? System.Threading.Thread.Sleep(3)
>>I do not think that sleeping between calls to loRnd.Next()) has any influence on the random value being returned
>>
>>
>>Just replace
>>Dim loRnd As Random = New Random
>>with
>>Static loRnd As Random = New Random
>>
>>Then I think you can drop
>>- loRandomValue
>>- the test for ( If lnNext = lnOldValue )
>>- the sleep()
>
>If I only have this, it generates the same value when being called in sequence:
>
>
>        ' Generate a password with alpha characters
>        ' expN1 Length of the password
>        Public Function GeneratePasswordAlpha(ByVal tnLength As Integer) As String
>            Dim lcPassword As String = ""
>            Dim llWroteConsonant As Boolean = False
>            Dim lnCounter As Integer = 0
>            Dim loConsonants() As Char = New Char() {"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v"}
>            Dim loDoubleConsonants() As Char = New Char() {"c", "d", "f", "g", "l", "m", "n", "p", "r", "s", "t"}
>            Dim loPasswordBuffer As New System.Text.StringBuilder
>            Dim loVowels() As Char = New Char() {"a", "e", "i", "o", "u"}
>            Statis loRnd As Random = New Random
>
>            For lnCounter = 0 To tnLength
>                If loPasswordBuffer.Length > 0 And Not llWroteConsonant And loRnd.Next(100) < 10 Then
>                    loPasswordBuffer.Append(loDoubleConsonants(loRnd.Next(loDoubleConsonants.Length)), 2)
>                    lnCounter = lnCounter + 1
>                    llWroteConsonant = True
>                Else
>                    If Not llWroteConsonant And loRnd.Next(100) < 90 Then
>                        loPasswordBuffer.Append(loConsonants(loRnd.Next(loConsonants.Length)))
>                        llWroteConsonant = True
>                    Else
>                        loPasswordBuffer.Append(loVowels(loRnd.Next(loVowels.Length)))
>                        llWroteConsonant = False
>                    End If
>                End If
>            Next
>
>            ' Size the buffer  
>            loPasswordBuffer.Length = tnLength
>
>            Return loPasswordBuffer.ToString
>        End Function
>
Hi,

I tested this. As Gregory says the likilihood of getting two consecutive identical results is purely statistical. With a password length of 5 I get a duplicate once every 40-150K operations. With a password length of 10 I'm currently past 12,000,000 without a duplicate.
I guess it shouldn't be hard to calculate the actual odds - but you get the picture.

Even with a 5 character password does having one duplicate per several tens of thousands of instances really present a problem?
And you're going to get duplicates anyway - why does the fact that they may be generated consecutively matter?
Regards,
Viv
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform