Hey
i'm developing a role based user authentication in my desktop application.i need to add few roles like Admin, operator, etc...
i can get users role if i have user name of the logged in user.but after logging in the username cannot be retrieved again.So it has to be saved as a global variable,but since having global variable is not good for the code i want to know the best way i can create a role based authentication for my desktop application in c#.

thanks in advanced.

Recommended Answers

All 3 Replies

can you give some specifics of your authentication method? implementation details, are you using windows integrated security? .net native roles? customized authentication levels developed by you?

Please provide us with details in order to get relevant help

can you give some specifics of your authentication method? implementation details, are you using windows integrated security? .net native roles? customized authentication levels developed by you?

Please provide us with details in order to get relevant help

i want to implement a customized authentication levels,in my DB i have few roles,and what i want is when user logged in i can check for the credentials validation.then i want to open a form according the role,(if role changes form changes.).when main form loads i check for the role.but i do not have an idea how i'm suppose to get the role in my main form.
also i can get the role when user login, because i have users username,but after login and my main form loads, i dont have a nice way to get the username.so i can't retrieve role.

hope you do understand,
thanks

Yes i understand :)

You can create a singleton class, set as public and initiated on login:

http://www.itexposed.com/forum/csharp/singleton-pattern/

Set your username and role definition in this class while making it public it will be available to all your application - implementing it in a singleton fashion will only allow one instance of your "role" class to avoid mishaps.

This has to be done after you validate the password of the user, pseudo code for it:

if (db.password = textbox.password)
{
Singleton s = new Singleton();
s.username = textbox.username;
s.roles = db.roles;
}

textbox info comes from form, whereas db info comes from db.

hope it helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.