Mensaje
De
23/11/2006 15:15:09
 
 
a
Todos
General information
Foro:
ASP.NET
Category:
Coding, syntax and commands
Título:
Bad routine to generate a password
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
ID de la conversación:
01172129
ID del mensaje:
01172129
Views:
91
I have this code to generate a password with letters and digits:
        ' Generate a password
        ' expN1 Length of the password
        Public Function GeneratePwd(ByVal tnLength As Integer) As String
            Dim lcPassword As String = ""
            Dim lnCounter As Integer = 0
            Dim lnRandom As Integer = 0

            For lnCounter = 1 To tnLength
                If lnCounter = 1 Or Int(Rnd() * 100) Mod 2 = 0 Then
                    lnRandom = Int(Rnd() * 25) + 97
                Else
                    lnRandom = Int(Rnd() * 9) + 48
                End If
                lcPassword = lcPassword + Chr(lnRandom)
            Next

            Return lcPassword
        End Function
This code has been converted from VFP. However, this does not work very well in .NET. It practically always generates the same password. Anyone would have something better to recommend?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Responder
Mapa
Ver