make my password generator generate 'complex' passwords
I've got a password generator in one of my scripts which generates 2 passwords and writes them to a database.
These passwords are later retrieved and set as the windows logon passwords for 2 users which are automatically created in a virtual machine.
I have a problem whereby my passwords are not always considered to be complex as far as windows is concerned.
I am using the following function to generate my passwords...
Public Function GeneratePassword(ByVal len As Integer) As String Dim str As String = "1234567890qwertyuio1pa2sd3fg4hj5kl6zx7cv8bn9mQ0WE1RT2YU3IO4PA5SD6FG7HJ8KL9ZX0CVBNM" Dim N As Integer = str.Length Dim rnd As New Random((Now.Hour * 3600 + Now.Minute * 60 + Now.Second) * 1000 + Now.Millisecond) Dim sb As New StringBuilder For l As Integer = 1 To len sb.Append(str.Substring(rnd.Next(0, N), 1)) Next Return sb.ToString End Function
Which is then called like this...
Dim vm_password1 As String = GeneratePassword(10)
How would i best go about modifying this code to ensure that each password generated contains 1 uppercase character, 1 lowercase character and one number?
Any help appreciated! :)
Of course you can extend this further, but here's the jist
Public Function fnGenPw() As String Dim RandomClass As New Random() Const legalAlpha As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" Const legalNums As String = "1234567890" Dim strbNewpw As New StringBuilder For i As Integer = 0 To 2 'first 3 characters are alpha Dim RandomNumber As Integer = RandomClass.Next(legalAlpha.Length - 1) strbNewpw.Append(legalAlpha.Chars(RandomNumber)) Next For i As Integer = 3 To 5 'characters 4,5,6 are numeric Dim RandomNumber As Integer = RandomClass.Next(legalNums.Length - 1) strbNewpw.Append(legalNums.Chars(RandomNumber)) Next For i As Integer = 6 To 9 'characters 7,8,9,10 are alpha Dim RandomNumber As Integer = RandomClass.Next(legalAlpha.Length - 1) strbNewpw.Append(legalAlpha.Chars(RandomNumber)) Next Return strbNewpw.ToString End Function