Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. retrive user rights from sql table

retrive user rights from sql table

Scheduled Pinned Locked Moved C#
databasequestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    I am using the following code to store public variables:

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace Takhlees
    {
    class public_class
    {
    // login;
    private static string user_login;

        public string login\_user\_login
        {
            get { return user\_login; }
            set { user\_login = value; }
        }
    
    }
    

    }

    and I want to create a table called user_rights with user_right_code and user_right_value fields..... The user_right_value field will be a bit with True or False and the user_right_code will have something like:

    ADD_OCCUPATION
    EDIT_OCCUPATION
    DELETE_OCCUPATION
    BROWSE _OCCUPATIONS
    BROWSE _GENDER
    BROWSE_NATIONALITY
    BROWSE_USERS
    ADD_USER
    EDIT_USER
    RESET_PASSWORD

    I want to know how can automatiocally retrive the user_right_code and user_right_value into public variables? do i have to create each and every code in the public_class?!!

    B 1 Reply Last reply
    0
    • J Jassim Rahma

      I am using the following code to store public variables:

      using System;
      using System.Collections.Generic;
      using System.Text;

      namespace Takhlees
      {
      class public_class
      {
      // login;
      private static string user_login;

          public string login\_user\_login
          {
              get { return user\_login; }
              set { user\_login = value; }
          }
      
      }
      

      }

      and I want to create a table called user_rights with user_right_code and user_right_value fields..... The user_right_value field will be a bit with True or False and the user_right_code will have something like:

      ADD_OCCUPATION
      EDIT_OCCUPATION
      DELETE_OCCUPATION
      BROWSE _OCCUPATIONS
      BROWSE _GENDER
      BROWSE_NATIONALITY
      BROWSE_USERS
      ADD_USER
      EDIT_USER
      RESET_PASSWORD

      I want to know how can automatiocally retrive the user_right_code and user_right_value into public variables? do i have to create each and every code in the public_class?!!

      B Offline
      B Offline
      Ben Fair
      wrote on last edited by
      #2

      Yes, in some form or fashion you need to have properties that tell you whether a particular user has a particular right. In this case you are relating a set of rights directly to a user. It is common, and may be beneficial, to use 'roles' where you construct a set of roles and each role has a set of rights associated with it, then a user is assigned a role rather than a set of individual priviledges. For example, a role named 'Admin' which has all the rights and one named 'ReadOnly' that only has the BROWSE rights. Choose whichever method works best for your needs. As far as retrieving the rights, the best OOP way would be to have a User class and some kind of security class that would contain information about the user's rights. The User class would be a composite in that it would contain a copy of the security class. It would seem pretty straight-forward to have the User class create and fill the security object when the User class is filled with the User data (perhaps invoking a query or stored procedure to retrieve the rights data where UserID=X). There are a myriad of ways of accomplishing this, I just gave one example to illustrate one way it could be done.

      Hold on a second here... Don't you think you might be putting the horse ahead of the cart?

      J 1 Reply Last reply
      0
      • B Ben Fair

        Yes, in some form or fashion you need to have properties that tell you whether a particular user has a particular right. In this case you are relating a set of rights directly to a user. It is common, and may be beneficial, to use 'roles' where you construct a set of roles and each role has a set of rights associated with it, then a user is assigned a role rather than a set of individual priviledges. For example, a role named 'Admin' which has all the rights and one named 'ReadOnly' that only has the BROWSE rights. Choose whichever method works best for your needs. As far as retrieving the rights, the best OOP way would be to have a User class and some kind of security class that would contain information about the user's rights. The User class would be a composite in that it would contain a copy of the security class. It would seem pretty straight-forward to have the User class create and fill the security object when the User class is filled with the User data (perhaps invoking a query or stored procedure to retrieve the rights data where UserID=X). There are a myriad of ways of accomplishing this, I just gave one example to illustrate one way it could be done.

        Hold on a second here... Don't you think you might be putting the horse ahead of the cart?

        J Offline
        J Offline
        Jassim Rahma
        wrote on last edited by
        #3

        but can you please explain a bit how can i use my properties to store the user rights? now if I have sql reader to read all the rights wheer user_id = 7 for example... I should read two columns, user_right_code and user_right_value?!! sorry but even after 10 cups of coffee I am still confused....!!

        J 1 Reply Last reply
        0
        • J Jassim Rahma

          but can you please explain a bit how can i use my properties to store the user rights? now if I have sql reader to read all the rights wheer user_id = 7 for example... I should read two columns, user_right_code and user_right_value?!! sorry but even after 10 cups of coffee I am still confused....!!

          J Offline
          J Offline
          Jassim Rahma
          wrote on last edited by
          #4

          I have a question.. is thete any way to have a variable called user_rights with a property for every right and its value? if that's possible then I can read the rights from the user_rights table and retrieve the following: user_rights[ALLOW_CREATE_CLIENT, True) user_rights[ALLOW_DELETE_CLIENT, False) where ALLOW_CREATE_CLIENT and ALLOW_DELETE_CLIENT are properties of user_rights where True and False are values for every property.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups