Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Generating a password with only alpha characters and dig
Message
 
To
21/04/2008 21:59:16
General information
Forum:
ASP.NET
Category:
Security
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01312284
Message ID:
01312323
Views:
19
This message has been marked as the solution to the initial question of the thread.
>I am using System.Web.Security.Membership.GeneratePassword() to generate a password. But, I would like to use a much simpler generator which would generate a password with only alpha characters and digits. Is there someone who has a small function for that?

give a try to this one:
    Private Function GeneratePassword(ByVal passwordLength As Integer) As String
        Dim Vowels() As Char = New Char() {"a", "e", "i", "o", "u"}
        Dim Consonants() As Char = New Char() {"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v"}
        Dim DoubleConsonants() As Char = New Char() {"c", "d", "f", "g", "l", "m", "n", "p", "r", "s", "t"}
        Dim wroteConsonant As Boolean  'boolean    
        Dim rnd As New Random
        Dim passwordBuffer As New System.Text.StringBuilder
        wroteConsonant = False

        For counter As Integer = 0 To passwordLength
            If passwordBuffer.Length > 0 AndAlso (wroteConsonant = False) AndAlso (rnd.Next(100) < 10) Then
                passwordBuffer.Append(DoubleConsonants(rnd.Next(DoubleConsonants.Length)), 2)
                counter += 1
                wroteConsonant = True
            Else
                If (wroteConsonant = False) AndAlso (rnd.Next(100) < 90) Then
                    passwordBuffer.Append(Consonants(rnd.Next(Consonants.Length)))
                    wroteConsonant = True
                Else
                    passwordBuffer.Append(Vowels(rnd.Next(Vowels.Length)))
                    wroteConsonant = False
                End If
            End If
        Next
        'size the buffer  
        passwordBuffer.Length = passwordLength
        Return passwordBuffer.ToString
    End Function
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform