954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

role based authentication in c# desktop application

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.

drax12
Newbie Poster
7 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

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

jfarrugia
Junior Poster
113 posts since May 2011
Reputation Points: 17
Solved Threads: 17
 

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

drax12
Newbie Poster
7 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

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

jfarrugia
Junior Poster
113 posts since May 2011
Reputation Points: 17
Solved Threads: 17
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: