I was commissioned to create a generator of random visual data generators. I came up with below that works, but its a little rude with its password criteria. I would like for each password that it generated to have at least 1 number in it, in upper and lower case. However, as I have encoded this, it will generate a random combination, which often leads to the fact that one of the criteria will be missed.
I had the game myself, and I had three lines: one with capital letters, one with lower case and the third with numbers. Once it has one of them, it will generate the rest of the password using my code. It does not seem very clean and I am having problems with this.
Can someone help point me in the right direction or help with the code below. Passwords must be between 6 and 20 characters long.
Thank you in advance
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click TextBox2.Text = GenerateCode() End Sub Private Function GenerateCode() As Object Dim intRnd As Object Dim intStep As Object Dim strName As Object Dim intNameLength As Object Dim intLength As Object Dim strInputString As Object strInputString = "1234567890ABCDEFGHIJKLMEOPQRSTUWXYZabcdefghijklmnopqrstuvwxyz" intLength = Len(strInputString) Randomize() strName = "" 'Check for valid numeric entry If Integer.TryParse(TextBox1.Text, intNameLength) And intNameLength >= 6 And intNameLength <= 20 Then For intStep = 1 To intNameLength intRnd = Int((intLength * Rnd()) + 1) strName = strName & Mid(strInputString, intRnd, 1) Next GenerateCode = strName Else TextBox1.Text =("Please enter a valid password length") End If End Function Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click My.Computer.Clipboard.SetText(TextBox2.Text) End Sub Private Sub TextBox1_Enter(sender As Object, e As EventArgs) Handles TextBox1.Enter TextBox1.Text = "" End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class
=========== UPDATE ===========
That's right, I changed my code a bit, so now I have three lines with different characters, 1 for the vertices, one for the slides and one for the numbers.
This allows me to have checkbox functionality in the form, which is a plus. I played with the code and now it generates passwords depending on what I choose with the help of checkboxes, which, as I say, are awesome, but I can not always guarantee that if I choose, number, upper and lower, I Iβll get a password containing all three, and sometimes the password will contain only numbers, even if all three fields are checked.
Guessing this is due to the fact that I just ask him to generate a random password using the characters that I give him, and there is no confirmation that he used all three parameters.
Any help on this would be awesome. I try and I do not just send messages and hope that someone will do the work for me. If someone can point me in the right direction, it would be great.
Here is my new code.
Public Function GenerateCode() Dim intRnd As Integer Dim intStep As Integer = Nothing Dim strname As String Dim intlength As Integer Dim strinputstring As String = "" Dim Numbers As String = "12345678901234567890" Dim Lower As String = "abcdefghijklmnopqrstuvwxyzyz" Dim Upper As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZYZ" Dim intnamelength As Integer = 1 If CheckBox1.Checked Then strinputstring &= Lower If CheckBox2.Checked Then strinputstring &= Numbers If CheckBox3.Checked Then strinputstring &= Upper intlength = Len(strinputstring) Integer.TryParse(NumericUpDown1.Text, intnamelength) Randomize() strname = "" For inStep = 1 To intnamelength intRnd = Int(Rnd() * intlength) + 1 strname = strname & Mid(strinputstring, intRnd, 1) Next Return strname End Function