Thursday, August 6, 2009

Snippet: Random Password Generator

A Simple Function for generating Random Password in .NET by passing length of password


Private Function generatePassword(ByVal passwordLength) As String
'Declare variables
Dim sDefaultChars, sMyPassword, iPickedChar As String
Dim iCounter, iDefaultCharactersLength, iPasswordLength As Integer
'Initialize variables
iPasswordLength = passwordLength
iDefaultCharactersLength = Len(sDefaultChars)
Randomize() 'initialize the random number generator
'Loop for the number of characters password is to have
For iCounter = 1 To iPasswordLength
'Next pick a number from 1 to length of character set
iPickedChar = Int((iDefaultCharactersLength * Rnd()) + 1)
'Next pick a character from the character set using the random number iPickedChar
'and Mid function
sMyPassword = sMyPassword & Mid(sDefaultChars, iPickedChar, 1)
Return sMyPassword
End Function

Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

0 comments : on " Snippet: Random Password Generator "