Solved

Password generator in VB6

Posted on 2000-05-05
3
323 Views
Last Modified: 2008-02-01
I'm a newbie in VB6 and I need a program to generate multiple passwords with letters and numbers of different lenght. Help me please...
0
Comment
Question by:rogerleblond
  • 2
3 Comments
 
LVL 13

Expert Comment

by:crazyman
ID: 2780388
This would make a string of random characters and numbers and random length between the values passed.


Public Function MakePassWord(minLength As Integer, maxLength As Integer) As String
      Dim x As Integer
      Dim y As Integer
      Dim z As Integer
      Dim strout As String
      Randomize
      x = Int((maxLength * Rnd) + minLength)
      For y = 1 To x
            Randomize
            z = CInt((255 * Rnd) + 1)
            strout = strout & Chr(z)
      Next y
      MakePassWord = strout
End Function

Private Sub Command1_Click()
      MakePassWord 1, 22
End Sub



u could easy mod it just to create letters and numbers and not strange characters
0
 
LVL 13

Expert Comment

by:crazyman
ID: 2780436
Heres a better one.



Option Explicit

Public Function MakePassWord(minLength As Integer, maxLength As Integer) As String
      Dim x As Integer
      Dim y As Integer
      Dim z As Integer
      Dim strout As String
      Randomize
      x = Int((maxLength * Rnd) + minLength)
      For y = 1 To x
            Randomize
            z = CInt((255 * Rnd) + 1)
            Do While (z < 65 Or z > 90) And (z < 97 Or z > 122) And (z > 57 Or z < 48)
                  Randomize
                  z = CInt((255 * Rnd) + 1)
            Loop
            strout = strout & Chr(z)
      Next y
      MakePassWord = strout
End Function

Private Sub Command1_Click()
     MsgBox (MakePassWord(1, 22))
End Sub
0
 
LVL 1

Accepted Solution

by:
garrenb earned 100 total points
ID: 2780968
Hi,

Here is a version on a routine I wrote to generate a password based on the user's name. The important line is the 'CODEUP' bit. This generates the small alogrithm. Hope this helps ...

Dim TheDate As Date   ' Declare variables.
        primedate = "15/03/1968"
        TheDate = Date
        dayz = DateDiff("d", primedate, TheDate)
        Password = TxtPword.Text
        passlong = Len(Password)
       
        Dim word(250)
       
        For loopy = 1 To passlong
            word(loopy) = Mid$(Password, loopy, 1)
        Next
       
        codeup = dayz
       
        For loopy = 1 To passlong
            codeup = codeup & ((Asc(word(loopy)) * 2) + dayz + 633) 'Add 633 This Could be anything
        Next
       
        Text2.Text = codeup
        TxtPword.Text = ""
        TxtRetype.Text = ""

        Call CmdCommit_Click
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question