Sunday, 15 January 2012

Storing/accessing user access roles C# Winforms -


I have created several client / server applications. I am working on a project that allows applications to access For a user logging is included. I am seeing the most effective and "simple" method of storing users' permissions after logging into the application which can be used primarily to limit access to fixed tabs.
I have created a "static class" for a user "detailed below:

  stable class user {public constant _USIDID; public static string _moduleName; public static string _userName; public static object [] Userdata (object [] _data row) {_userID = (int) _dataRow [0]; _userName = (string) _data rau [1]; _moduleName = (string) _data roll [2]; back _moduleName;}}  

When a user logs in and accepts them , I want to store _moduleName objects in memory so that I can control those tabs that can be accessed on the main form tab control, if; the user has been assigned the following roles in the database: "Sales laser "," Buy ", only after the entry form is hidden, you can see the relevant tab on the form using switch-case block only. For example, by saying for example, I can store the user ID and user name in the main form:

Here we process the logged data from the user: < / P>

  DataAccess _dal = New DataAccess (); Switch (_dal.ValidateLogin (txtUserName.Text, txtPassword.Text)) {case DataAccess.ValidationCode.ConnectionFailed: MessageBox.Show ("database server connection fail!"); break; Case DataAccess.ValidationCode .LoginFailed: MessageBox.Show ("Login failed!"); _dal.RecordLogin (errMsg, txtUserName.Text, workstationID, incorrect); break; Case DataAccess.ValidationCode. Successful Login: frmMain frmMain = new frmMain (); _dal.GetUserPrivList (errMsg, 2); // & LT; Here I reach my DB and get user permissions based on the current login. FrmMain.Show (); This.Hide (); break; Default: Break; } Private Zero frmMain_Load (Object Sender, EventArgs e) {int UserID = User._userID; }  

This works fine, however, _modules objects have many permissions / roles, which are defined in the database, how can I store more than one value and Can block access through switch-case?

If I understand correctly, you store permissions / roles as a value I want to be able to do a database per user

I believe you can write a database field such as integer such as: RolesID . You type the value of the flag to the database field, something like this:

  [flag] Public anonym ROLES {Administrator = 1, user = 2, otherroll 3 = 4, otherroll 4 = 8}  

You should be able to read that value and declare it as a field:

  ROLES userRoles = GetRoleValueFromDB ();  

I'm pretty sure I did it earlier.

HH ...


No comments:

Post a Comment