+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 14

Thread: Random Password Generator

  1. #1
    Newbie Sauce is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    7

    Random Password Generator

    What needs to be thrown in where the arrow is pointing in the attachment?
    I am a nub in VB. Also, I am using Visual Studio 2008.

    Code:
    Declare function GenerateCode Lib "kernel32" ALias "_lopen" (ByVal lpPathName As String, By Val ireadwrite As Long)As Long
    
    
    Public Class Form1
    
        Private Sub Text1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Text1.TextChanged
    
        End Sub
    
        Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click
            Text1 = GenerateCode() 'make sure ur textbox is called Text1
        End Sub
    End Class
    
    Public Function GenerateCode()
        strInputString = "1234567890abcdefghijklmnopqrstuvwxyz" 'these are the characters which will be in the password
    
        intLength = Len(strInputString)
    
        intNameLength = 7 'edit this according to how long u want ur password to be
    
        Randomize() ' jus to make it random :D
    
        strName = ""
    
        For intStep = 1 To intNameLength
            intRnd = Int((intLength * Rnd) + 1)
    
            strName = strName & Mid(strInputString, intRnd, 1)
        Next
    
        GenerateCode = strName
    End Function
    Attached Thumbnails Random Password Generator-6-25-2009-10-49-11-am.png  

  2. #2
    Moderator Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe's Avatar
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Age
    16
    Posts
    8,784
    Blog Entries
    5

    Re: Random Password Generator

    It should be "ByVal" not "By Val". Just remove the space.

  3. #3
    Newbie Sauce is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    7

    Re: Random Password Generator

    The entire declaration is wrong now.

  4. #4
    Moderator Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe's Avatar
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Age
    16
    Posts
    8,784
    Blog Entries
    5

    Re: Random Password Generator

    What's the error?

  5. #5
    Newbie Sauce is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    7

    Re: Random Password Generator

    Code:
    Declare Function GenerateCode Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal ireadwrite As Long) As Long
    "Statement is not in a valid namespace"

  6. #6
    Moderator Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe's Avatar
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Age
    16
    Posts
    8,784
    Blog Entries
    5

    Re: Random Password Generator

    I think I missed some point on what you're trying to do... Why do you even declare the function at the top? Can't you just do it like this:

    Code:
        Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click
            Text1.Text = GenerateCode() 'make sure ur textbox is called Text1
        End Sub
    
    
        Public Function GenerateCode() As String
            Dim strInputString As String = "1234567890abcdefghijklmnopqrstuvwxyz" 'these are the characters which will be in the password
    
            Dim intLength As Integer = Len(strInputString)
    
            Dim intNameLength As Integer = 7 'edit this according to how long u want ur password to be
    
            Randomize() ' jus to make it random :D
    
            Dim strName As String = ""
    
            For intStep = 1 To intNameLength
                Dim intRnd As Integer = Int((intLength * Rnd()) + 1)
    
                strName = strName & Mid(strInputString, intRnd, 1)
            Next
    
            GenerateCode = strName
        End Function
    Please tell me if I understood it wrong...

  7. #7
    Newbie Sauce is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    7

    Re: Random Password Generator

    Well, Public Function GenerateCode() is not a declared function, so a friend told me to that I need to declare it, hence the top code.

  8. #8
    Moderator Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe's Avatar
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Age
    16
    Posts
    8,784
    Blog Entries
    5

    Re: Random Password Generator

    How do you want the GenerateCode() to be used then, only from the click? And didn't my code work?

    It's hard to know what to do to fix the error, because when I write this...:

    Code:
    Declare Function GenerateCode Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal ireadwrite As Long) As Long
    ...it works fine.

  9. #9
    Newbie Sauce is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    7

    Re: Random Password Generator

    Well, I have a text box and a button. When someone clicks the button, a code gets generated in the text box.

  10. #10
    Moderator Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe has a reputation beyond repute Vswe's Avatar
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Age
    16
    Posts
    8,784
    Blog Entries
    5

    Re: Random Password Generator

    But then it doesn't even needs to be public if the button and the text box are in the same form:

    Code:
       Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click
            Text1.Text = GenerateCode() 'make sure ur textbox is called Text1
        End Sub
    
    
        Private Function GenerateCode() As String
            Dim strInputString As String = "1234567890abcdefghijklmnopqrstuvwxyz" 'these are the characters which will be in the password
    
            Dim intLength As Integer = Len(strInputString)
    
            Dim intNameLength As Integer = 7 'edit this according to how long u want ur password to be
    
            Randomize() ' jus to make it random :D
    
            Dim strName As String = ""
    
            For intStep = 1 To intNameLength
                Dim intRnd As Integer = Int((intLength * Rnd()) + 1)
    
                strName = strName & Mid(strInputString, intRnd, 1)
            Next
    
            GenerateCode = strName
        End Function
    Try if this works, it works for me...

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Random password generation
    By Divya in forum PHP Forum
    Replies: 7
    Last Post: 07-03-2009, 06:42 AM
  2. Need Help Creating A Random Generator
    By KingCrimson250 in forum PHP Forum
    Replies: 4
    Last Post: 06-21-2009, 11:08 AM
  3. random number generator
    By chili5 in forum JavaScript and CSS
    Replies: 4
    Last Post: 06-01-2008, 06:55 AM
  4. Floating Point random number generator
    By Paradine in forum PHP Tutorials
    Replies: 0
    Last Post: 08-26-2007, 02:09 PM
  5. How do I program a random generator?
    By eddiewillers in forum General Programming
    Replies: 4
    Last Post: 07-24-2007, 02:26 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts