%REM Copyright 2012 Conxsys Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License %ENDREM ' 'Function GeneratePassword 'Description: Generates a random password 'History: 'v1: Initial version. (cdavis@conxsys.com) 08Feb2012 '---------------------------------------------------------- Public Function GeneratePassword(length As Integer, useSpecialChar As Boolean) As String On Error GoTo ErrHandler Randomize Dim pass As String Dim charCount, char As Integer If length > 63 Then Let length = 63 'Notes passwords cannot be more than 63 characters long For charCount = 1 To length Let char = Round((Rnd() * 1000), 0) If useSpecialChar And (CInt(char) >= 33 And CInt(char) =< 126) Then Let pass = pass & Chr$(char) ElseIf (CStr(char) Like "[4][8-9]") Or (CStr(char) Like "[5][0-7]") Or _ (CStr(char) Like "[6][5-9]") Or (CStr(char) Like "[7-8][0-9]") Or _ (CStr(char) = "90") Or (CStr(char) Like "[9][7-9]") Or _ (CStr(char) Like "[1][0-1][0-9]") Or (CStr(char) Like "[1][2][0-2]") Then Let pass = pass & Chr$(char) Else Let charCount = charCount - 1 End If Next charCount Let GeneratePassword = pass Exit Function ErrHandler: Error Err, Error & { on line } & Erl & { in } & GetThreadInfo(1) & Chr$(13) End Function