Login Username stored

mufasa

New member
Joined
May 6, 2013
Messages
1
Programming Experience
3-5
Hi There

I have a login with username and password that authenticate and authorize the users.

Where is the best place to store the username for use anywhere in the win forms application?

Thx
Mufasa
 
One option would be to create a singleton class to represent the logged on user. You can then access the one and only instance of that class anywhere in the app. Here's a simple example of such a class that could be used in this case:
internal class CurrentUser
{
    private static CurrentUser _instance;

    public static CurrentUser Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = new CurrentUser();
            }

            return _instance;
        }
    }

    public string UserName { get; set; }

    private CurrentUser()
    {

    }
}
You can use:
C#:
CurrentUser.Instance.UserName
to get and set the user name of the current user anywhere in your code.
 
Back
Top Bottom