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! :)

Answers


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

Need Your Help

i want to set typeface for GridView

java android eclipse

i want to set typeface for TextView which is the adapter of GridView. i need to access typeface from Asset folder.

No log folder is created under each task directory in cuckoo

sandbox malware sandbox-solution

I am running cuckoo 0.6 and everything is fine. My virtual machine is accessed by cuckoo and performs analysis. but after each analysis only tcpdupm.pcap and report folder are created in the /stor...