none
password generator in vb8

    Question

  • how to create password generator in vb8   small alpha and numbers to textbox anybody tell me thanks 
    Sunday, April 15, 2012 7:31 PM

Answers

  • can you tell me code for this

    Homework?

    Learn arrays and the random class. Set an array of characters such as 

    Dim MyArray() As String = {"a", "b", "c"} ' and so on

    Next, work with the random class by getting a random number and use that random number as an index for the array.

    Dim MyRand As New Random()
    Dim i As Integer = MyRand.Next(MyArray.Count)
    Console.WriteLine(MyArray(i))

    If you put together those 4 lines, you will have a random letter generator. There's your starting point.

    My cents to the other members of the MSDN, if you are going to post some complex solution, don't. Keep things simple. Remember that VB.NET oftentimes is a starting point for many programmers and giving them difficult solutions will only make them more frustrated.

    Best regards,

    - Jordan


    Jordan St. Godard | Microsoft® Community Contributor 2011

    double twoCents = .02;
    Console.WriteLine("$" + twoCents.ToString());

    Sunday, April 15, 2012 9:49 PM
  • Take this code and make it better (limit the password length is a good start)

    form with a button and 3 text boxes

    Imports System.Security.Cryptography
    Public Class Form1
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim CryptoArray(23) As Byte ' set up an array to hold cryptographic random numbers - size can be changed
            Dim InitArray(15) As Byte   ' set up an array for the GUID generator - size cannot be changed
            Dim MyRandom As New Random  ' set up a new random number generator
            TextBox1.Clear() ' erase contents of texbox
            TextBox2.Clear() ' erase contents of texbox
            TextBox3.Clear() ' erase contents of texbox
    
            For index As Integer = 0 To 15 ' prepare to fill the GUID init array
                InitArray(index) = CByte(MyRandom.Next(0, 256))
            Next
            Dim Mypassword As Guid = New Guid(InitArray)
            TextBox1.Text = Mypassword.ToString.Replace("-", "") ' GUID's contain "dashes", so get rid of them
    
            Dim Crypto As RNGCryptoServiceProvider = New RNGCryptoServiceProvider ' set up a new cryptographic provider
            Crypto.GetBytes(CryptoArray)                                          ' fill the array
            TextBox2.Text = Convert.ToBase64String(CryptoArray)                   ' convert to Base64(text) and display
    
            For index = 1 To 32
                Dim Rnd As Integer = MyRandom.Next(0, 100)
                If Rnd < 33 Then TextBox3.Text &= Chr(MyRandom.Next(48, 58)) '0-9 = 48-57
                If Rnd >= 33 And Rnd < 66 Then TextBox3.Text &= Chr(MyRandom.Next(65, 91)) 'A-Z = 65-90
                If Rnd >= 66 Then TextBox3.Text &= Chr(MyRandom.Next(97, 123)) 'a-z = 97-122
            Next
        End Sub
    End Class
    

    Monday, April 16, 2012 9:48 PM

All replies

  • Decide on the chars allowed, put them in an array. Decide on the min and max length (or just fix it at say 10).

    Use a random number generator to pick a number in range 0 to number of chars in array. In a loop, that pick a  rn and use it as index into array of allowed chars, append the picked char to a string, when loop finished set textbox text to string.

    Of course you may want something more sophisticated.


    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

    Sunday, April 15, 2012 7:46 PM
  • can you tell me code for this
    Sunday, April 15, 2012 8:23 PM
  • Have you decided on the characters you want to use and have you loaded them into an array?

    Have you decided on whether the password will be fixed length, or will it have a random size from some minimum to some maximum?  What are those numbers?

    Have you created a random number generator and tried to use it to access the array of allowed characters?  If so, what was the code that you used and what was the result?   Did you have a problem getting that code to compile, or was the problem that the result wasn't what you expected?

    Sunday, April 15, 2012 9:32 PM
  • Well I could but why don't you try and write it? A function to return passwords would take about 8 lines of code.

    I knocked up a quick console app that does it - with a main sub to test that it generates different password the total line count is 24 (inclusing blank lines and the module gubbins VS inserts.

    If you try it and it does not work, I'll be happy to help fix it.

    PS instead of an array of chars, you could use a string that has the allowed chars and get a substring starting at index given by rn (only needs to be length 1).


    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.


    • Edited by Riced Sunday, April 15, 2012 9:38 PM Added PS
    Sunday, April 15, 2012 9:33 PM
  • can you tell me code for this

    Homework?

    Learn arrays and the random class. Set an array of characters such as 

    Dim MyArray() As String = {"a", "b", "c"} ' and so on

    Next, work with the random class by getting a random number and use that random number as an index for the array.

    Dim MyRand As New Random()
    Dim i As Integer = MyRand.Next(MyArray.Count)
    Console.WriteLine(MyArray(i))

    If you put together those 4 lines, you will have a random letter generator. There's your starting point.

    My cents to the other members of the MSDN, if you are going to post some complex solution, don't. Keep things simple. Remember that VB.NET oftentimes is a starting point for many programmers and giving them difficult solutions will only make them more frustrated.

    Best regards,

    - Jordan


    Jordan St. Godard | Microsoft® Community Contributor 2011

    double twoCents = .02;
    Console.WriteLine("$" + twoCents.ToString());

    Sunday, April 15, 2012 9:49 PM
  • Hi,

    Does anybody finds the solution for this?

    Monday, April 16, 2012 4:55 AM
  • There's no chance of finding a solution until OP has indicated what rules the password must comply with, such as how long it needs to be, what characters are valid within the password, and whether there is some restriction on the maximum (eg, not all numeric) or minimum (eg, at least two special characters) characters that can be used. Without that information it is not possible to design the solution, let alone code it.
    Monday, April 16, 2012 5:57 AM
  • Yes. As I said in an earlier post I knocked up a simple VB app to do this.

    Some people might consider this as a "Microsoft" reply i.e it correctly and fuly answers your question but is useless. LOL


    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

    Monday, April 16, 2012 8:57 AM
  • Take this code and make it better (limit the password length is a good start)

    form with a button and 3 text boxes

    Imports System.Security.Cryptography
    Public Class Form1
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim CryptoArray(23) As Byte ' set up an array to hold cryptographic random numbers - size can be changed
            Dim InitArray(15) As Byte   ' set up an array for the GUID generator - size cannot be changed
            Dim MyRandom As New Random  ' set up a new random number generator
            TextBox1.Clear() ' erase contents of texbox
            TextBox2.Clear() ' erase contents of texbox
            TextBox3.Clear() ' erase contents of texbox
    
            For index As Integer = 0 To 15 ' prepare to fill the GUID init array
                InitArray(index) = CByte(MyRandom.Next(0, 256))
            Next
            Dim Mypassword As Guid = New Guid(InitArray)
            TextBox1.Text = Mypassword.ToString.Replace("-", "") ' GUID's contain "dashes", so get rid of them
    
            Dim Crypto As RNGCryptoServiceProvider = New RNGCryptoServiceProvider ' set up a new cryptographic provider
            Crypto.GetBytes(CryptoArray)                                          ' fill the array
            TextBox2.Text = Convert.ToBase64String(CryptoArray)                   ' convert to Base64(text) and display
    
            For index = 1 To 32
                Dim Rnd As Integer = MyRandom.Next(0, 100)
                If Rnd < 33 Then TextBox3.Text &= Chr(MyRandom.Next(48, 58)) '0-9 = 48-57
                If Rnd >= 33 And Rnd < 66 Then TextBox3.Text &= Chr(MyRandom.Next(65, 91)) 'A-Z = 65-90
                If Rnd >= 66 Then TextBox3.Text &= Chr(MyRandom.Next(97, 123)) 'a-z = 97-122
            Next
        End Sub
    End Class
    

    Monday, April 16, 2012 9:48 PM
  • Thanks
    Tuesday, April 17, 2012 5:48 AM
  • Or try this:

    Module Module1
       Sub Main()
          'Declare these to use function
          Dim randGen As Random = New Random()
          Dim allowed As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
          Dim pwLen As Integer = 10

          'Simple test of function, instead of writing to console, put in textbox
          For x = 1 To 20
             Dim pw As String = GeneratePassword(randGen, allowed, pwLen)
             Console.WriteLine(pw)
          Next
          Console.ReadLine()
       End Sub

       Function GeneratePassword(ByVal rnGen As Random, ByVal theChars As String, ByVal len As Integer) As String
          Dim s As String = ""
          For i As Integer = 1 To len
             Dim index As Integer = rnGen.Next(0, theChars.Length)
             s = s & theChars.Substring(index, 1)
          Next
          Return s
       End Function
    End Module

    It's what I referred to in my first post. You might also consider the first line of my sig. :)


    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

    Tuesday, April 17, 2012 3:44 PM