OpenNTF.org - Generates a random password /
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
Generates a random password / string 
Rating:
Rating: 4 , Number of votes: 2 
Contributor:
Alex Robinson 
Category:
Lotusscript 
Type:
String functions 
Notes Version:
R6.x 
Last Modified:
15 Jul 2004 
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
Function rndPassword(length As Integer) As String


'Generates a random string "length" characters long

For i = 0 To length
character = ""
charType = Round(2 * Rnd + 1,0)
Select Case charType

Case 1 : character = Chr(Round((57-48)*Rnd + 48,0)) ' a number
Case 2 : character = Chr(Round((90-65)*Rnd + 65,0)) ' a upper case letter
Case 3 : character = Chr(Round((122-97)*Rnd + 97,0)) 'a lower case letter

End Select
rndPassword = rndPassword + character
Next

End Function

Usage / Example
'8 Character random password

password = rndPassword(8)
 Comments
Posted by Michael Woehrer on 07/30/2004 12:52:24 PMQuite helpful script
Thanks Alex, this is quite helpful.
I use this code in this way (due to 'Option Declare' and standard prefixes):
Public Function RandomPassword(intLength As Integer) As String
'Generates a random string "intLength" characters long
Dim i As Integer
Dim intCharType As Integer
Dim strCharacter As String
For i = 1 To intLength
strCharacter = ""
intCharType = Round(2 * Rnd + 1,0)
Select Case intCharType
Case 1 : strCharacter = Chr(Round((57-48)*Rnd + 48,0)) ' a number
Case 2 : strCharacter = Chr(Round((90-65)*Rnd + 65,0)) ' a upper case letter
Case 3 : strCharacter = Chr(Round((122-97)*Rnd + 97,0)) 'a lower case letter
End Select
RandomPassword = RandomPassword + strCharacter
Next
End Function
Regards,
Michael
 Add your comment!