dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB7
Expertise: beginner
Dec 1, 2003

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


GetRandomPassword - Generating a random password with the specified length

' Generate a random password with the specified length. The password will only 
' contain digits and letters (either lowercase or uppercase)
'
' Example: generating a password of 8 chars
'    Dim password As String = GetRandomPassword(8)

Function GetRandomPassword(ByVal length As Integer) As String
    Static rand As New Random
    Dim password As New System.Text.StringBuilder(length)

    For i As Integer = 1 To length
        Dim charIndex As Integer
        ' allow only digits and letters
        Do
            charIndex = rand.Next(48, 123)
        Loop Until (charIndex >= 48 AndAlso charIndex <= 57) OrElse (charIndex _
            >= 65 AndAlso charIndex <= 90) OrElse (charIndex >= 97 AndAlso _
            charIndex <= 122)
        ' add the random char to the password being built
        password.Append(Convert.ToChar(charIndex))
    Next
    Return password.ToString()
End Function
Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date