Click here to Skip to main content
13,087,235 members (64,854 online)
Rate this:
Please Sign up or sign in to vote.
Hi all,
I want to create a simple Login form for my Windows Application. I have tried some methods and found some examples on the web, but they are not completely suitable for Winform application. So, could you please show some examples for a login form (or user control) which contains username and password field and check databese if the user id and password is valid. Then, if valid close or dispose itself and open Main form. Thanks in advance...
Posted 15-May-11 11:27am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

For winforms login:

User Login For WinForm Applications[^]

For Opening another form after logging in:

Multiple Subsequent "Main" Forms in C# Apps[^]
SAKryukov 15-May-11 18:15pm
My 5; I also voted for these two articles -- good way to answer multiple questions...
H.Johnson 16-May-11 9:04am
Thanks for reply. Actually I had seen your nice example before submitting this question. But, my aim is not use windows authentication. Instead, I need a simple application that have a Main Form and a Login Form. By starting the application firt the Login Form appears and user enter username & password to the login form. Then, by pressing the OK button, the login form checks username & password on database. If username & password is valid, the MainForm will open. If not, the Login Form closes and application exits. Could you give me such a sample making this procedure please? Thanks in advance...
H.Johnson 24-May-11 9:40am
Thanks for reply. Actually both pages are useful. On the other hand, I would like to inform a great sample on the page
Thanks to all answered my question. Beside solution answer, I have voted all the useful comments :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You're probably not going to find one one simple example that has exactly what you are looking for. I think your best option is to just start making your own example and come back with specific questions when you run into trouble.

This article[^] looks like a good overview about storing passwords. I thought it might help get you started.

Here is a tip/trick[^] that might help, too.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Here's what I would do...

Login Form:

Create a form "frmLogIn", and give is a public property (bool) of IsAuthorized.
Add two text boxes to the form, make one of them a password box (using masking characters).
Add a cancel button (make it the cancel for the dialog), and an OK button (make it the OK for the dialog).
On Cancel, set IsAuthorized to false and close the form (returning control to main()).
On OK, do database verification and set IsAuthorized appropriately (depending on db verification).


When the program starts, launch the login form initially checking for DialogResult == OK.

If OK, launch your main application form... else just let it drop through main() and exit.

If you have any specific questions on those basic items you can pose those and see what kind of tips you can get as kschuler suggested.

Good luck!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 16 May 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100