Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 142169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:53:37+00:00 2026-05-11T07:53:37+00:00

I have this databases: table<User>(UserID,Name,Surname,Username,Password,Email) , table<Role>(RoleID,RoleName,Description) , and table<UsersInRole>(UserID,RoleID) . I create a

  • 0

I have this databases: table<User>(UserID,Name,Surname,Username,Password,Email), table<Role>(RoleID,RoleName,Description), and table<UsersInRole>(UserID,RoleID). I create a login authentication with username and password to access to the application (with Linq ToSql to store data), and it is right. Now I wish to create a role for each user, but I don’t know how work out it; I saw some features about it but it refers to web.app.

This is the code of the procedure that applies to login:

public partial class Window1 : Window     {         public Window1()         {             InitializeComponent();         }           public bool ValidateApplicationUser(string userName, string password)         {           {                 var AuthContext = new DataClasses1DataContext();                 var query = from c in  AuthContext.Users                             where (c.Username == userName.ToLower() && c.Password == password.ToLower())                             select c;                  if(query.Count() != 0 )                 {                     return true;                 }                  return false;             }          }          private void mahhh(object sender, RoutedEventArgs e)         {             bool authenticated = true;             {                 if (usernameTextBox.Text !='' && passwordTextBox.Text != '')                 {                     authenticated = ValidateApplicationUser(usernameTextBox.Text , passwordTextBox.Text);                 }              }             if (!authenticated)             {                 MessageBox.Show('Invalid login. Try again.');             }             else             {                 MessageBox.Show('Congradulations! You're a valid user!');                 Window3 c = new Window3();                 c.ShowDialog();                 this.Close();             }         }     } 

I don’t know how to implement a method to assign a role to the user. Do you have any idea or suggest to make it right?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:53:38+00:00Added an answer on May 11, 2026 at 7:53 am

    First, try not to store passwords in the database; it is better to store a hash. I’m not quite sure what you mean ‘assign a role to the user’ – are you having difficulty getting the role from the db? Or are you unsure what to do with it afterwards? If the latter, the ‘principal’ is the way to go; at the simplest level:

            string username = ...         string[] roles = ...         Thread.CurrentPrincipal = new GenericPrincipal(             new GenericIdentity(username), roles); 

    Now you can use role-based security, either declarative or imperative.

    Declarative:

        [PrincipalPermission(SecurityAction.Demand, Role='ADMIN')]     public void Foo()     { // validated automatically by the .NET runtime ;-p      } 

    Imperative:

        static bool IsInRole(string role)     {         IPrincipal principal = Thread.CurrentPrincipal;         return principal != null && principal.IsInRole(role);     }     ...     bool isAdmin = IsInRole('ADMIN'); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following database model: [User] Id Name [Role] Id Name [UserRole] UserId
i have an orders table that has a userID column i have a user
I have this classes: public class User { [Key] public Guid UserId { get;
I have a simple database with a Persons table UserId, Name,DOB The table contains
I have a table in my database like this: [id] [uniqueidentifier] NOT NULL, [user_id]
I have this database structure, SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; CREATE TABLE IF NOT EXISTS `announces` (
I have this table structure on a SQL Server 2008 R2 database: CREATE TABLE
I have this enormous database : # # Dropping tables # DROP TABLE IF
i have database table like this +-------+--------------+----------+ | id | ip | date |
I have a database table using an enum. This is already working with hibernate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.