Model login constraints based on time
Posted
by DaDaDom
on Stack Overflow
See other posts from Stack Overflow
or by DaDaDom
Published on 2010-01-26T08:18:39Z
Indexed on
2010/03/28
10:03 UTC
Read the original article
Hit count: 336
Good morning,
for an existing web application I need to implement "time based login constraints". It means that for each user, later maybe each group, I can define timeslots when they are (not) allowed to log in into the system. As all data for the application is stored in database tables, I need to somehow create a way to model this idea in that way.
My first approach, I will try to explain it here:
- Create a tree of login constraints (called "timeslots") with the main "categories", like "workday", "weekend", "public holiday", etc. on the top level, which are in a "sorted" order (meaning "public holiday" has a higher priority than "weekday")
- for each top level node create subnodes, which have a finer timespan, like "monday", "tuesday", ...
- below that, create an "hour" level: 0, 1, 2, ..., 23. No further details are necessary.
- set every member to "allowed" by default
- For every member of the system create a
1:n
relationshipmember:timeslots
which defines constraints, e.g. a member A may haveA:monday-forbidden
andA:tuesday-forbidden
- Do a depth-first search at every login and check if the member has a constraint. Why a depth first search? Well, I thought that it may be that a member has the rules:
A:monday->forbidden
, A:monday-10->allowed
, A:mondey-11->allowed
So a login on monday at 12:30 would fail, but one at 10:30 succeed.
For performance reasons I could break the relational database paradigm and set a flag for every entry in the member-to-timeslots-table which is set to true if the member has information set for "finer" timeslots, but that's a second step.
Is this model in principle a good idea? Are there existing models?
Thanks.
© Stack Overflow or respective owner