Solved

Password generator in VB6

Posted on 2000-05-05
3
318 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now