Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitlePrompt the user for a serial number the first time the program runs
DescriptionThis example shows how to prompt the user for a serial number the first time the program runs in Visual Basic 6.
Keywordsserial number, password, one time, one-time
CategoriesSoftware Engineering
 
Thanks to Gamal Ahmed.

When the program runs, it loads a password from the Registry and compares it to the desired value. If the value matches, the program displays the program's main form. If the value doesn't match, it displays its first form, which lets the user enter the password.

 
Private Sub Form_Load()
    Command1.Caption = "&Next"
    Label1.Caption = "2B7Q8"
    Label1.Font.Size = 12
    Text1.FontSize = 12
    Me.Caption = "GAF_PASS"

    ' Load the saved value from the registry.
    Text1.Text = GetSetting(APP_NAME, SECTION_NAME, " " & _
        "Text1", Text1.Text)
    If Text1 = Label1.Caption Then
        Form2.Show
        Unload Me
    End If
End Sub
 
When the user enters a passwords and clicks the button, the program checks the password. If the value is correct, the program stores it in the Registry for next time and displays the main form.
 
Private Sub Command1_Click()
    If Text1 = Label1.Caption Then
        Form2.Show
        Unload Me
    Else
        MsgBox "Not valid Key-Number"
    End If
End Sub
 
This program stores the correct password in a Label control. In a more secure application, you would not want to store the plain password in a control because other processes can read another program's controls. Instead you should do something such as make the product serial number hash to a magic value and store that value. When the user enters a serial number, hash it and see if it matches the magic value.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated