'++LotusScript Development Environment:2:5:(Options):0:74
%REM
Library RandomPassword
Created 10.07.2014 by
Description: Comments for Library
%END REM
Option Public
Option Declare
'++LotusScript Development Environment:2:5:(Forward):0:1
Declare Sub Initialize
Declare Function pickZufallUndEntferne ( stringArray As Variant ) As String
Declare Function ArrayToString ( stringArray As Variant ) As String
Declare Function findeLeerePosZufaellig ( stringArray As Variant ) As Integer
Declare Function berechnePassword As String
'++LotusScript Development Environment:2:5:(Declarations):0:10
Dim S As String
Dim Sunten As Integer
Dim Soben As Integer
Dim T As String
Dim Tunten As Integer
Dim Toben As Integer
Dim G As String
Dim Gunten As Integer
Dim Goben As Integer
Dim K As String
Dim Kunten As Integer
Dim Koben As Integer
Dim Z As String
Dim Zunten As Integer
Dim Zoben As Integer
Dim sonder (1 To 2 ) As String
Dim gkz (1 To 6 ) As String
Dim Laenge_min As Integer
Dim Laenge_max As Integer
Dim Laenge_akt As Integer
'++LotusScript Development Environment:2:2:Initialize:1:10
Sub Initialize
' ---------------------------------------------------------------------------------------
' init Konstanten
' ---------------------------------------------------------------------------------------
S = "!§$%&/()=*'_:;,.-<>"
Sunten = 1
Soben = Len ( S )
T = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Tunten = 1
Toben = Len ( T )
G = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Gunten = 1
Goben = Len ( G )
K = "abcdefghijklmnopqrstuvwxyz"
Kunten = 1
Koben = Len ( K )
Z = "0123456789"
Zunten = 1
Zoben = Len ( Z )
Laenge_min = 8
Laenge_max = 14
Laenge_akt = ( Laenge_max - Laenge_min )*Rnd() + Laenge_min
' ---------------------------------------------------------------------------------------
' init Variablen
' ---------------------------------------------------------------------------------------
Dim i As Integer
i = 0
Dim tmp As Integer
For i = 1 To 2
tmp = ( Soben - Sunten )*Rnd() + Sunten
sonder ( i ) = Mid ( S, tmp, 1 )
Next
For i = 1 To 2
tmp = ( Goben - Gunten )*Rnd() + Gunten
gkz ( i ) = Mid ( G, tmp, 1 )
Next
For i = 3 To 4
tmp = ( Koben - Kunten )*Rnd() + Kunten
gkz ( i ) = Mid ( K, tmp, 1 )
Next
For i = 5 To 6
tmp = ( Zoben - Zunten )*Rnd() + Zunten
gkz ( i ) = Mid ( Z, tmp, 1 )
Next
Dim erg As String
erg = ArrayToString ( sonder )
erg = erg + ArrayToString ( gkz )
End Sub
'++LotusScript Development Environment:2:1:pickZufallUndEntferne:5:8
%REM
Function pickZufallUndEntferne
Description: Comments for Function
%END REM
Function pickZufallUndEntferne ( stringArray As Variant ) As String
Dim max As Integer
max = UBound( stringArray )
Dim tmp As Integer
tmp = ( max - 1 ) * Rnd() + 1
Dim erg As String
erg = stringArray ( tmp )
While ( erg = "" )
tmp = ( max - 1 ) * Rnd() + 1
erg = stringArray ( tmp )
Wend
stringArray (tmp) = ""
pickZufallUndEntferne = erg
End Function
'++LotusScript Development Environment:2:1:ArrayToString:2:8
Function ArrayToString ( stringArray As Variant ) As String
Dim erg As String
erg = ""
ForAll x In stringArray
erg = erg + x
End ForAll
ArrayToString = erg
End Function
'++LotusScript Development Environment:2:1:findeLeerePosZufaellig:5:8
%REM
Function findeLeerePosZufaellig
Description: Bedenke, dass es lange dauert in einem grossen
Array, das nur noch eine Leerstelle hat, die freie Stelle so zu "finden".
Vorschlag, Skizze: Sei n Anzahl Leerstellen und es gebe ein
Mapping für 0 <= i <= n für den Index der Leerstelle. Berechne k als Zufallszahl
zwischen 0 und n-1 und ermittle durch das Mapping den gesuchten Index.
%END REM
Function findeLeerePosZufaellig ( stringArray As Variant ) As Integer
Dim erg As Integer
erg = 0
Dim s As String
s = stringArray ( erg )
Dim max As Integer
max = UBound( stringArray )
While ( s <> "" )
erg = ( max - 1 ) * Rnd() + 1
s = stringArray ( erg )
Wend
findeLeerePosZufaellig = erg
End Function
'++LotusScript Development Environment:2:1:berechnePassword:5:8
%REM
Function berechnePassword
Description: Comments for Function
%END REM
Function berechnePassword As String
Call Initialize()
Dim erg () As String
ReDim erg ( Laenge_akt ) As String
' Kein SZ am Anfang und Ende.
erg (0) = pickZufallUndEntferne ( gkz )
erg ( Laenge_akt-1 ) = pickZufallUndEntferne ( gkz )
Dim rndPos As Integer
' Grossbuchstaben, Kleinbuchstaben und Ziffern verteilen.
ForAll x In gkz
If Not ( x = "" ) Then
rndPos = findeLeerePosZufaellig( erg )
erg ( rndPos ) = x
End If
End ForAll
' Sonderzeichen verteilen.
ForAll x In sonder
rndPos = findeLeerePosZufaellig( erg )
erg ( rndPos ) = x
End ForAll
' Nun enthaelt erg 8 nicht-leere Zeichen.
' Die Leerstellen fuellen mit Zufallsstelle aus T.
ForAll x In erg
If ( x = "" ) Then
rndPos = ( Toben - Tunten )*Rnd() + Tunten
x = Mid ( T, rndPos, 1 )
End If
End ForAll
berechnePassword = ArrayToString( erg )
End Function