RandomPassword
Returns a string whose content and length are selected randomly within the constraints specified by the parameters. This function is intended to be used to generate unpredictable passwords.
Syntax
RandomPassword([Val [, MinLength [, MaxLength]]])
Parameters
Val
Type: Text
Optional. The characters allowed in the password. If Val is omitted or empty, “0123456789” is used.
MinLength
Type: Long
Optional. The minimum length of the password. If MinLength is omitted or is less than 1, the minimum length is set to 8.
MaxLength
Type: Long
Optional. The maximum length of the password. If MaxLength is omitted or is less than MinLength, the maximum length is set to MinLength.
(return)
Type: Text
A password whose content and length are selected randomly within the constraints specified by the parameters
Remarks
If Val begins with "[" and ends with "]", Val is interpreted as a regular expression, which enables ranges of characters to be specified without listing them all explicitly. For example, "[0-9a-fA-F]" is equivalent to "0123456789abcdefABCDEF".
The selection is truly random, like
SetRandomSeed, so the results are not reproducible.
This function has no effect on the randomization state of the calling program.
Example
The following script generates a password that is between 10 and 16 characters long and contains a random selection of digits and lower-case letters:
Dim MyPassword
MyPassword = RandomPassword("[a-z0-9]", 10, 16)
See also