Results 1 to 10 of 10

Thread: WinForms Login

  1. #1

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    WinForms Login

    C# version here.

    Here are some simple steps to create login functionality in your WinForms app.

    1. Create a new WinForms project.
    2. Add a new form to act as the Login dialogue. You can use the item template supplied with VS or create your own.
    3. Open the ApplicationEvents code file from the button on the Application tab of the project properties.
    4. Create a Startup event handler using the drop-down lists at the top of the code file and add the following code:
    vb.net Code:
    1. Using loginDialogue As New LoginForm1
    2.     e.Cancel = (loginDialogue.ShowDialog() <> DialogResult.OK)
    3. End Using
    5. Add the logic to your Login form to validate the credentials supplied by the user. You may like to use this as a basis.
    6. If the login succeeds set your Login dialogue's DialogResult property to OK. If the user presses the Cancel button or fails to login within a prescribed maximum number of attempts then set the DialogResult to something else.

    If the user logs in successfully the app will start normally, otherwise it will exit without ever creating a main form.
    Last edited by jmcilhinney; Dec 14th, 2008 at 10:35 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  2. #2
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: WinForms Login

    How to perform step number 4 ?

  3. #3

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: WinForms Login

    Quote Originally Posted by LuxCoder
    How to perform step number 4 ?
    I think you should be able to work that out for yourself. How many drop-down lists do you see at the top of the code file?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: WinForms Login

    I have attached a VS 2008 project that demonstrates logging into a WinForms app by validating against a database. An Access database (MDB format) with three existing users is included in the project.

    Note that the login form contains code to validate using a Data Source and code to do it all manually. There is a Boolean constant that can be toggled to change which gets used. I added a scalar query to the TableAdapter in the designer to provide the validation functionality.
    Attached Files Attached Files
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    New Member
    Join Date
    Jul 2010
    Posts
    9

    Re: WinForms Login

    Quote Originally Posted by jmcilhinney View Post
    I have attached a VS 2008 project that demonstrates logging into a WinForms app by validating against a database. An Access database (MDB format) with three existing users is included in the project.

    Note that the login form contains code to validate using a Data Source and code to do it all manually. There is a Boolean constant that can be toggled to change which gets used. I added a scalar query to the TableAdapter in the designer to provide the validation functionality.
    Any chance you could convert this to vb I tried using an online converter but it keeps giving me an error

    thnaks

  6. #6

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: WinForms Login

    Quote Originally Posted by mikejs View Post
    Any chance you could convert this to vb I tried using an online converter but it keeps giving me an error

    thnaks
    Um, it is VB.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    New Member
    Join Date
    Jul 2010
    Posts
    9

    Re: WinForms Login

    Quote Originally Posted by jmcilhinney View Post
    Um, it is VB.
    Doh idiot, I am stuck trying to get it to connect to a remote SQL server I have added the remote connection strings to my app config and kept the other referances the same for now (same DB tables) if I run the app with tableadaptor I get "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done." error on this line

    Code:
    Return adapter.GetUserCountByUserNameAndPassword(Me.UsernameTextBox.Text.Trim(), _
                                                                 Me.PasswordTextBox.Text).Value > 0
    if I try to run it as a data adaptor I get this error "An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'."

    and ideas

    thanks

    M

  8. #8
    New Member
    Join Date
    Jul 2010
    Posts
    9

    Re: WinForms Login

    Quote Originally Posted by mikejs View Post
    Doh idiot, I am stuck trying to get it to connect to a remote SQL server I have added the remote connection strings to my app config and kept the other referances the same for now (same DB tables) if I run the app with tableadaptor I get "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done." error on this line

    Code:
    Return adapter.GetUserCountByUserNameAndPassword(Me.UsernameTextBox.Text.Trim(), _
                                                                 Me.PasswordTextBox.Text).Value > 0
    if I try to run it as a data adaptor I get this error "An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'."

    and ideas

    thanks

    M
    I have sorted out my remote conection can anyone point me in the right direction in order to md5 hash my password field or is it possible to have a secure tunnel (connection to the SQL server?)

    thanks

    Mike

  9. #9
    New Member
    Join Date
    Jul 2010
    Posts
    9

    Re: WinForms Login

    Sorry me again is it possible to have the login redirect to a diffrent form if user is in say the admin table
    I know I need to run a query like

    compaire username and password in User table if >0 form1.show() else comapure username and password in Admin table if >0 admin.frm.show()

    I am just not sure where I would add this logic to your code any suggestions thanks

    M

  10. #10

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: WinForms Login

    @mikejs: you're going beyond the scope of this thread. You should start a new thread in the VB.NET forum.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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