我已經遠遠好得多,功能齊全的VB代碼,隨機密碼生成器。這是我自己編寫的VB Express程序。用戶可以選擇密碼長度並從上限,下限,數字或特殊字符中選擇。您可以生成8至25個字符的無盡密碼。這裏是代碼和.RAR文件來下載完整的程序。最好的是...它的免費!
\\\======================================================================\\\
Option Explicit On
'---------------------------------------------------------------------
'---------------------------------------------------------------------
'---------------------- Password Generator ® -------------------------
'---------------------- Author: Chirag Patel -------------------------
'---------------------- Current Version: 1.x -------------------------
'---------------------- Date: August, 14, 2015 -----------------------
'---------------------- License: FREE License Program ----------------
'---------------------------------------------------------------------
'---------------------------------------------------------------------
Public Class frmPassGen
'Declearing main intiger which will hold password
Dim Letters As New List(Of Integer)
Public Function Info()
'This button provide information about author
Dim Infor As String
Infor = MsgBox("Program: Password Generator ®" & _
vbCrLf & "---------------------------------" & _
vbCrLf & "Version: 1.0" & _
vbCrLf & "Programmer: Chirag Patel" & _
vbCrLf & " " & _
vbCrLf & "Legal Verbiage" & _
vbCrLf & "-----------------" & _
vbCrLf & "This program is FREE License program." & _
vbCrLf & " " & _
vbCrLf & "Thank you." & _
vbCrLf & "Chirag Patel", MsgBoxStyle.Information, "Password Generator")
cmbLength.Focus()
End Function
Public Function Clear()
On Error Resume Next
'Clears ALL
cmbLength.Text = "000"
cmbLength.Focus()
txtPassword.Text = "... Your Password ..."
chkUpper.Checked = False
chkLower.Checked = False
chkNumber.Checked = False
chkSpecial.Checked = False
txtLPass.Text = ""
cmbNpass.Text = "000"
End Function
Public Function Upper()
'Add ASCII Codes For Upper Case Letters
For i As Integer = 65 To 90
Letters.Add(i)
Next
End Function
Public Function Lower()
'Add ASCII Codes For Lower Case Letters
For i As Integer = 97 To 122
Letters.Add(i)
Next
End Function
Public Function Numbers()
'Add ASCII Codes For Numbers
For i As Integer = 48 To 57
Letters.Add(i)
Next
End Function
Public Function Special()
'Add ASCII Codes For Special Characters
For i As Integer = 33 To 47
Letters.Add(i)
Next
End Function
Public Function uRemove()
Dim rRnd As New Random
Dim rSB As New System.Text.StringBuilder
Dim trPass As Integer
'Remove ASCII code for Upper case letters
For i As Integer = 65 To 90
Letters.Remove(i)
Next
'Remove ASCII Codes For Lower Case Letters
For i As Integer = 97 To 122
Letters.Remove(i)
Next
'Remove ASCII Codes For Numbers
For i As Integer = 48 To 57
Letters.Remove(i)
Next
'Remove ASCII Codes For Special Characters
For i As Integer = 33 To 47
Letters.Remove(i)
Next
'Remove cache
For count As Integer = -1 To Val(cmbLength.Text)
trPass = rRnd.Next(0, Letters.Count)
rSB.Append(Chr(Letters(trPass)))
Next
txtPassword.Text = rSB.ToString
End Function
Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
On Error Resume Next
'Exit Program
Me.Close()
End
End Sub
Private Sub txtPassword_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPassword.KeyDown
On Error Resume Next
'Doesn't allow to change password
txtPassword.Text = ""
MsgBox("You cannot change password here.", MsgBoxStyle.Information, "Password Generator")
txtPassword.Text = "... Your Password ..."
cmbLength.Text = "000"
cmbNpass.Text = "000"
cmbLength.Focus()
End Sub
Private Sub frmPassGen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
On Error Resume Next
'Default Settings
cmbLength.Text = "000"
cmbNpass.Text = "000"
cmdOK.Enabled = False
txtPassword.Text = "... Your Password ..."
cmbLength.Focus()
lbltTime.Text = TimeOfDay
Me.Text = "Password Generator - " & Format(Date.Now, "dddd, MM-dd-yyyy")
End Sub
Private Sub cmbLength_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbLength.SelectedIndexChanged
On Error Resume Next
'Enable Generate Button
If cmbLength.Text = "000" Then
cmdOK.Enabled = False
Else
cmdOK.Enabled = True
End If
End Sub
Private Sub cmdInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdInfo.Click
On Error Resume Next
'Display Program Info
Call Info()
End Sub
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
On Error Resume Next
For i As Integer = 0 To Val(cmbNpass.Text) 'Number of passwords need to generate
'Disabled OK (Generate) Button when no options are selected
If chkLower.Checked = False And chkNumber.Checked = False And chkSpecial.Checked = False And chkUpper.Checked = False Then
MsgBox("Please select at list one of the four options to generate new random password.", MsgBoxStyle.Information, "...Password Generator")
cmbLength.Focus()
cmdOK.Enabled = False
End If
'Decleration of Variables
Dim Rnd As New Random ' Generates Random Strings
Dim SB As New System.Text.StringBuilder ' Bings the String generated by Rnd
Dim tPass As Integer ' Temp Variable to hold the generated string in temp continer
'Condition...
If cmbLength.Text = "000" And cmbNpass.Text = "000" Then
Beep()
MsgBox("You must select the length and numbers password.", MsgBoxStyle.Information, "Password Generator")
Else
cmdOK.Enabled = True
End If
'Creating password string...
For count As Integer = 1 To Val(cmbLength.Text) 'Length of password
tPass = Rnd.Next(0, Letters.Count)
SB.Append(Chr(Letters(tPass)))
Resume
Next
If Val(i) = 1 Then 'One Password Generated
txtPassword.Text = SB.ToString
Else
txtPassword.Text = SB.ToString 'More Password Generated
txtLPass.Text += txtPassword.Text & vbNewLine
End If
Next
'Disabled OK (Generate) Button when no options are selected
If chkLower.Checked = False And chkNumber.Checked = False And chkSpecial.Checked = False And chkUpper.Checked = False Then
cmbLength.Text = "000" And cmbNpass.Text = "000"
End If
End Sub
Private Sub cmbLength_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbLength.KeyDown
On Error Resume Next
'Doesn't allow users to alter the value in selection (drop down box)
cmbLength.Text = ""
cmbLength.Text = "000"
MsgBox("Sorry, you cannot alter the value in this area.", MsgBoxStyle.Information, "Password Generator")
End Sub
Private Sub chkUpper_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkUpper.CheckedChanged
If chkUpper.Checked = True Then
Call Upper()
Else
'Remove ASCII code for Upper case letters
For i As Integer = 65 To 90
Letters.Remove(i)
Next
End If
End Sub
Private Sub chkLower_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkLower.CheckedChanged
If chkLower.Checked = True Then
Call Lower()
Else
'Remove ASCII Codes For Lower Case Letters
For i As Integer = 97 To 122
Letters.Remove(i)
Next
End If
End Sub
Private Sub chkNumber_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkNumber.CheckedChanged
If chkNumber.Checked = True Then
Call Numbers()
Else
'Remove ASCII Codes For Numbers
For i As Integer = 48 To 57
Letters.Remove(i)
Next
End If
End Sub
Private Sub chkSpecial_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSpecial.CheckedChanged
On Error Resume Next
'Checks if the Special Checkbox is checked
If chkSpecial.Checked = True Then
Call Special()
Else
'Remove ASCII Codes For Special Characters
For i As Integer = 33 To 47
Letters.Remove(i)
Next
End If
End Sub
Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click
On Error Resume Next
'Call Clear
Call Clear()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
lbltTime.Text = TimeOfDay
End Sub
Private Sub txtLPass_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtLPass.KeyDown
On Error Resume Next
'Doesn't allow Edit...
MsgBox("You cannot alter the password here.", MsgBoxStyle.Information, "Password Generator")
Call Clear()
End Sub
Private Sub cmbNpass_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbNpass.SelectedIndexChanged
On Error Resume Next
'Enable Generate Button
If cmbNpass.Text = "000" Then
cmdOK.Enabled = False
Else
cmdOK.Enabled = True
End If
End Sub
末級
,你能否告訴我們在一個表格形式的代碼?它可能被壓縮成「只是一種形式」。 –
這已經爲你完成:) – AaronHatton
這不會是非常安全的,因爲你公開所有你生成的密碼很容易! – Nanne