Results 1 to 11 of 11

Thread: [RESOLVED] Register/login System

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    28

    Resolved [RESOLVED] Register/login System

    How would I make it so that the contents of the form are saved and they can be used to log into the application.

    Can you make it so that there is more than one account?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Register/login System

    If you are talking about saving stuff from application session to application session, i.e., after your app closes and then get info next time app is used, you have several options and here are some of them:

    1. Use a file to store the whatever contents you want saved. Maybe an INI file
    2. Use the registry to store the information
    3. Use a database

    If you are talking about passing information from one form to another then
    1. Any form's controls can be referenced from other forms. From Form2: Me.Caption = Form1.Text1.Text
    2. You can use public variables placed in a module. Public variables in a module are accessible to everything in your project
    3. You can use public variables within the form that are accessed same way as controls
    4. You can build public functions, sub and properties within a form

    More details would be helpful depending on what scenarios you are looking at.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    28

    Re: Register/login System

    ok im going with the first option,
    how do you call something from a module to a form?
    i guessed a couple times but i failed...

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Register/login System

    Can you be more specific with "something"? It's really easy but depends on what you are referring to
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    28

    Re: Register/login System

    I just copied this from a game login, could i use this to make the contents of the form save and make a login?
    I edited all the locations so it goes to the folder i want it to



    Code:
    Function AccountExist(ByVal name As String) As Boolean
        Dim filename As String
        filename = "\Ea\" & Trim(name) & ".ini"
    
        If FileExist(filename) Then
            AccountExist = True
        End If
    
    End Function
    
    Function PasswordOK(ByVal name As String, ByVal Password As String) As Boolean
        Dim filename As String
        Dim RightPassword As String * NAME_LENGTH
        Dim nFileNum As Long
    
        If AccountExist(name) Then
            filename = App.Path & "\Ea\" & Trim$(name) & ".ini"
            nFileNum = FreeFile
            Open filename For Binary As #nFileNum
            Get #nFileNum, ACCOUNT_LENGTH, RightPassword
            Close #nFileNum
    
            If UCase$(Trim$(Password)) = UCase$(Trim$(RightPassword)) Then
                PasswordOK = True
            End If
        End If
    
    End Function
    
    Sub AddAccount(ByVal index As Long, ByVal name As String, ByVal Password As String)
        Dim i As Long
        
        ClearPlayer index
        
        Player(index).Login = name
        Player(index).Password = Password
    
        Call SavePlayer(index)
    End Sub
    Sub SavePlayer(ByVal index As Long)
        Dim filename As String
        Dim f As Long
    
        filename = App.Path & "\Ea\" & Trim$(Player(index).Login) & ".ini"
        
        f = FreeFile
        
        Open filename For Binary As #f
        Put #f, , Player(index)
        Close #f
    End Sub

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Register/login System

    It really depends on what you want saved. That example appears to save a UDT (user defined type) to file, per user account. An INI file can be simple or complex. You should first determine what exactly you want to save. Then it's a matter of saving: create file, write contents, close file. When time comes to read: Open file if it exists, read contents, close file. How you write the contents dictates how you read/parse the contents.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    28

    Re: Register/login System

    yeah i was going for a udt account
    so how would i call AddAccount in a form if it's in a module?

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Register/login System

    In the module, simple declare the AddAccount routine as PUBLIC. Any publicly delcared variable, function, sub, property in a module can be called from anywhere within your project, at any time. Note that not including the Public or Private keyword makes it Public by default.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    28

    Re: Register/login System

    So i said screw the game one, and i made my own can someone revise it for me?
    Code:
    Public Sub CreateUser()
    ' ' ' ' ' ' ' ' ' ' ' ' '
    ' ' ' Create User ' ' ' '
    ' ' ' ' ' ' ' ' ' ' ' ' '
    
    
    
    Dim Username, Password As String
    Username = Form2.Text1.Text
    Password = Form2.Text3.Text
    
    Open App.Path & "/Ea/" & Username & ".ini" For Output As info
    
    Print info, Username
    Print info, Password
    Close info
    
    
    Exit Sub
    
    
    End Sub
    
    Public Sub Login()
    ''''''''''''''''''
    ' ' ' LOGIN' ' ' '
    ''''''''''''''''''
    On Error GoTo err
    Dim Username As String
    Dim Password As String
    Dim CorrUser As String
    Dim CorrPass As String
    
    Username = frmLogin.txtUserName.Text
    Password = frmLogin.txtPassword.Text
    
    Open App.Path & "/Ea/" & Username & ".ini" For Input As #Login
    
    Input #Login, CorrUser
    Input #Login, CorrPass
      Close #Login
    
    If Username = "" Then MsgBox "Please Enter a Valid Username.", vbOKOnly, "Login Failed"
     ElseIf Username = CorrUser Then
       If CorrPass <> Password Then MsgBox "Invalid Password", vbOKOnly, "Login Failed"
       ElseIf Password = CorrPass Then
         MsgBox "Welcome " + Username
         Me.Hide
         Form3.Show
       Else
        End If
     Else
      End If
    
    
    Exit Sub
    err: MsgBox "Login Failed Try Again", vbCritical, "Login Failed"
    
    End Sub

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    28

    Re: Register/login System

    So i tried to use the code in my previous relpy as a module, and when i activate it on the form it comes up with an error,
    it says:
    "Compile Error:
    Method not valid without suitable object"
    and highlights this portion:
    Code:
    Print info, Username
    Extra info:
    This code is in Public Sub CreateUser()
    I am using a command button to call this
    Code:
    Command3_click()
    Call CreateUser
    Please Help


    Previous Reply:


    Quote Originally Posted by Willbillion View Post
    So i said screw the game one, and i made my own can someone revise it for me?
    Code:
    Public Sub CreateUser()
    ' ' ' ' ' ' ' ' ' ' ' ' '
    ' ' ' Create User ' ' ' '
    ' ' ' ' ' ' ' ' ' ' ' ' '
    
    
    
    Dim Username, Password As String
    Username = Form2.Text1.Text
    Password = Form2.Text3.Text
    
    Open App.Path & "/Ea/" & Username & ".ini" For Output As info
    
    Print info, Username
    Print info, Password
    Close info
    
    
    Exit Sub
    
    
    End Sub
    
    Public Sub Login()
    ''''''''''''''''''
    ' ' ' LOGIN' ' ' '
    ''''''''''''''''''
    On Error GoTo err
    Dim Username As String
    Dim Password As String
    Dim CorrUser As String
    Dim CorrPass As String
    
    Username = frmLogin.txtUserName.Text
    Password = frmLogin.txtPassword.Text
    
    Open App.Path & "/Ea/" & Username & ".ini" For Input As #Login
    
    Input #Login, CorrUser
    Input #Login, CorrPass
      Close #Login
    
    If Username = "" Then MsgBox "Please Enter a Valid Username.", vbOKOnly, "Login Failed"
     ElseIf Username = CorrUser Then
       If CorrPass <> Password Then MsgBox "Invalid Password", vbOKOnly, "Login Failed"
       ElseIf Password = CorrPass Then
         MsgBox "Welcome " + Username
         Me.Hide
         Form3.Show
       Else
        End If
     Else
      End If
    
    
    Exit Sub
    err: MsgBox "Login Failed Try Again", vbCritical, "Login Failed"
    
    End Sub

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Register/login System

    The Print command requires an object or file number

    Object: Picture1.Print userName will print the username value to the picturebox. In a form, the form is default if no object provided. In a module, you must provide the object or file handle

    File number: Print #1, userName will print the username value to an opened file
    You should avoid hardcoding file numbers, rather use FreeFile() to return one. Look at the VB FAQs linked in my signature below. There are good examples you can use for file I/O.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width