Asp.net Identity Good practice authorization

Asked

Viewed 285 times

1

I have my user using Asp.net Identity for authentication as usual I have my class implementing iuser

public class usuario: IUser 
{
public User(){...}

        public User(string userName) (){...}

        public string Id { get; set; }

        public string UserName { get; set; }

        public string PasswordHash { get; set; }
}

Okay, I also have my class Person

Where all my registrations (customer, supplier, seller, etc.) inherit from Pessoa.

My question is:

It would be bad practice for me to implement the Iuser in a class of inherited person?

Public class usuario: Pessoa,IUser {
}

Or just have a class to connect both entities, thus doing PERSON Y has a user on the system

public class UsuarioPessoa {

public Pessoa Pessoa {get;set;}
public usuario usuario {get;set;}
}

At first a Seller who inherits from Person, will have a user to login to the system. and only 1.

  • In fact it depends on how you intend to implement these relationships, another idea (which I use) is to have an optional dependency on User Person, or vice versa: public Pessoa Pessoa { get; set; }. I would avoid the second example, because there may be cases of a Person having relations with one or more Users and also vice versa. Unless that is desirable.

1 answer

1


Depends on your goal.

I agree to Pessoa and Usuário be separated if Pessoa don’t need to have a Usuário, or if a Pessoa possess several Usuários (2nd example).

Otherwise, it is best to implement everything in the class Pessoa (first example).

  • At first a Seller who inherits from Person, will have a user to login to the system. and only 1.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.