About This Code
Brief Description:
Generate a random password
Contributor:
Andrew Jones
Last Modified:
17 Jun 2002
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
Sub Initialize
Dim x As Integer
Dim i As Integer
Dim nchar() As String
For x = 0 To 127 'ASCII-Code
Select Case x
Case 48 To 57
Redim Preserve nchar(i)
nchar(i) = Chr$(x)
i = i + 1
Case 97 To 122
Redim Preserve nchar(i)
nchar(i) = Chr$(x)
i = i + 1
End Select
Next
For j = 1 To 8 'generate the password
pw = pw + nchar(Rnd(x)*i)
Next
'Display the password in a password field
End Sub
Usage / Example
Comments
Posted by Chris Bordeleau on 01/06/2006 08:05:01 AMgreat function... just changed it a bit
Function genPassword(iLength As Integer) As String
Dim x As Integer
Dim i As Integer
Dim j As Integer
Dim z As Integer
Dim nchar() As String
For x = 0 To 127 'ASCII-Code
Select Case x
Case 48 To 57
Redim Preserve nchar(i)
nchar(i) = Chr$(x)
i = i + 1
Case 97 To 122
Redim Preserve nchar(i)
nchar(i) = Chr$(x)
i = i + 1
End Select
Next
For j = 1 To iLength 'generate the password
z = Rnd(x)*i
While z > 35
z = z - 35
Wend
genPassword = genPassword + nchar(z)
Next
End Function