产生随机密码
在编程过程中,可能会导致生成密码。 以下功能将生成随机选择的字符(最多10个字符)的密码(此密码很容易增加)。 所需的字符数作为参数传递。
与选择自己的密码相反,使用这种类型的过程可以提高安全性。
'Form code - frmPasswordGenerate
Private Declare Function GetTickCount Lib "kernel32" () As Long
Public Function PassGen(nLen As Integer)
Dim range As Collection
Dim ivalue, icount, iLen As Long
Dim pass As String
Set range = New Collection
range.Add ("0")
range.Add ("1")
range.Add ("2")
range.Add ("3")
range.Add ("4")
range.Add ("5")
range.Add ("6")
range.Add ("7")
range.Add ("8")
range.Add ("9")
icount = 0
ivalue = 0
iLen = range.Count
Do Until icount = nLen
Randomize
ivalue = CByte(Mid(CStr(Rnd(GetTickCount)), 3, 2))
If ivalue > 0 And ivalue <= iLen Then
icount = icount + 1
pass = pass & range(ivalue)
End If
Loop
PassGen = pass
End Function
Private Sub cmdGeneratePassword_Click()
MsgBox PassGen(8)
End Sub
From: https://bytes.com/topic/visual-basic/insights/641549-generate-random-password