11. april 2004 - 13:34Der er
11 kommentarer og 3 løsninger
Random tekststreng
Hejsa..
Jeg er ved at lave et program hvor programmet skal lave et tilfældigt password der indeholder store bogstaver, små bogstaver, tal og special tegn hver halve time. Det jeg ikke kan finde ud af er hvordan man laver det random password... Man kan jo bare bruge en timer til det andet...
ID = CInt(10) + 1 r = Rnd * 50 MsgBox prompt:=r For i = 0 To 20 If CInt(r) > 0 And CInt(r) < 26 Then myStr = myStr + Chr(97 + CInt(r)) r = Rnd * 100 Next
Private Sub Command1_Click() Me.Caption = GenPass(20) End Sub
Public Function GenPass(ByVal intLen As Integer) As String Dim strOut As String Dim intLast As Integer Dim intValue As Integer
Randomize Time
Do Until Len(strOut) = intLen
Select Case Int((3 * Rnd) + 1) Case 1: intValue = (Int((26 * Rnd) + 1) + 64) 'A til Z Case 2: intValue = (Int((26 * Rnd) + 1) + 96) 'a til z Case 3: intValue = (Int((10 * Rnd) + 1) + 47) '0 til 9 End Select
If intLast <> intValue Then strOut = (strOut & Chr$(intValue)) intLast = intValue End If
Loop GenPass = strOut End Function '----------------------------- Form1 -----------------------------
Private Sub Command1_Click() Me.Caption = GenPass(20) End Sub
Public Function GenPass(ByVal intLen As Integer) As String Dim strOut As String Dim intLast As Integer Dim intTegn As Integer Dim intValue As Integer
Const strTegn As String = "!#¤%&/()=?¨^`´+*'.:,;-_<>\"
Randomize Time
Do Until Len(strOut) = intLen
Select Case Int((4 * Rnd) + 1) Case 1: intValue = (Int((26 * Rnd) + 1) + 64) 'A til Z Case 2: intValue = (Int((26 * Rnd) + 1) + 96) 'a til z Case 3: intValue = (Int((10 * Rnd) + 1) + 47) '0 til 9 Case 4 intTegn = Int((Len(strTegn) * Rnd) + 1) intValue = Asc(Mid$(strTegn, intTegn, 1)) End Select
If intLast <> intValue Then strOut = (strOut & Chr$(intValue)) intLast = intValue End If
Loop GenPass = strOut End Function '----------------------------- Form1 -----------------------------
Private Sub Command1_Click() Me.Caption = GenPass(20) End Sub
Public Function GenPass(ByVal intLen As Integer) As String Dim strOut As String Dim intTegn As Integer Dim intValue As Integer
Const strTegn As String = "!#¤%&/("")=?¨^`´+*'.:,;-_<>\"
Randomize Time If (Len(strTegn) + 62) > intLen Then Do Until Len(strOut) = intLen
Select Case Int((4 * Rnd) + 1) Case 1: intValue = (Int((26 * Rnd) + 1) + 64) 'A til Z Case 2: intValue = (Int((26 * Rnd) + 1) + 96) 'a til z Case 3: intValue = (Int((10 * Rnd) + 1) + 47) '0 til 9 Case 4 intTegn = Int((Len(strTegn) * Rnd) + 1) intValue = Asc(Mid$(strTegn, intTegn, 1)) End Select
If InStr(strOut, Chr$(intValue)) = 0 Then strOut = (strOut & Chr$(intValue)) End If
Loop End If GenPass = strOut End Function '----------------------------- Form1 -----------------------------
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.