Interface programming - use them for security class?

Ok, I read the stack overflow question โ€œWhat does it mean toโ€œ program for an interface โ€andโ€œ understand. โ€I understand the benefits of using interfaces (at least I think I know). However, I have a little problem with by the fact that I'm currently working on what will be my first implementation of the interface.

I am creating a class to authenticate users on my site. I wrote it using static methods, so I can execute User.Authenticate (username, password). For me it is nice and easy. We look forward to three other types of members that can authenticate. Their authentication methods will point to different tables, etc. However, they still have to authenticate, change their password when changing passwords, to check their security question, etc. This seems perfect for the interface, but I have problems wrapping around how to do this.

User types are users, doctors, brokers, employers. For me, each class must implement a security interface that defines the methods mentioned above.

Can someone shed some light on how to do this And if my thinking is right?

+3
source share
7 answers

You might want to take a look at ASP.NET/Microsoft membership . From your description, it sounds like you have users with different roles (doctor, broker, etc.).

+2
source

"Interface programming" means designing a set of methods and properties that are the public "signature" of the functionality or service that the class provides.

You declare it as an interface, and then implement it in a class that implements the interface.

, , , .

.

.

, User.Authenticate(username, password) - , , ? ?

- , , . (, , , ) , .

, , , , .

+1

, . . , , , , . , , ILogon - , , "" , .

, -, , , .

+1

, , .

Cade - . , , .

//Defined Classes
class UserType1 : SecurityInterface
class UserType2 : SecurityInterface
class UserType3 : SecurityInterface

//Use classes
SecurityInterface authentication = GetCorrectUserTypeObject(); //the methds gets the correct UserType object base on who is supposed to authenticate.

authentication.DoAuthenticate(); 
+1

. , , , . , , , . , . , , - (, SQL AD, SQL).

, , , ( MemberhipProvider), , . / , .

+1

- , - .

0

All types of users you mentioned are users. I worked on a variety of sites that had a limited approach in which they referred to the first type of user that was written as โ€œuserโ€ on the site, and then any additional user types added later were just awkward.

My suggestion: do not call one of your users "user". These are all users of different types or roles.

0
source

Source: https://habr.com/ru/post/1702145/


All Articles