Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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...
BR.
Posted

For winforms login:

User Login For WinForm Applications[^]

For Opening another form after logging in:

Multiple Subsequent "Main" Forms in C# Apps[^]
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 15-May-11 18:15pm    
My 5; I also voted for these two articles -- good way to answer multiple questions...
--SA
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 http://www.codeproject.com/KB/cpp/Login_Control.aspx
Thanks to all answered my question. Beside solution answer, I have voted all the useful comments :)
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.
 
Share this answer
 
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).

Main:

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!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900