Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I maintain user login details in a Winforms application?

Tags:

c#

winforms

Hi can I'm very new to windows forms. Here I want to maintain state (like session in web applications) in windows forms.

Actually i want to store user login details in session. But i think there is no concept of session in winforms. So what is the alternative method to handle this type of situation.

Regards, Nagu

like image 728
Nagu Avatar asked Jul 27 '09 04:07

Nagu


2 Answers

There is no concept of Session variables in windows forms. What you can do is:

  1. Create a internal class that holds the User name and password and any other variables and enumerations needed across the application (Something like Common.cs). These can be accessed through public properties across the application.

  2. Have a parameterized constructor for all the forms and send the user name and the password whenever you are showing the form.

like image 136
danish Avatar answered Oct 19 '22 09:10

danish


public class MyForm : Form
{
     private string userName;
     private string password;
}

Since windows forms are statefull (opposed to stateless for web forms), you can just use a field in your Form class.

like image 21
Paul van Brenk Avatar answered Oct 19 '22 10:10

Paul van Brenk