Providing temporary access to your application

ASP.NET, PHP

Let’s say you need to provide users temporary access to your application. You create a user, set their access to ‘temporary’ and after 24 hours they should not be able to log on to your application. And, of course, you need this to happen automatically.

1. Add two more fields to the login table.

access – varchar(50). This field will store values like “temporary” or “inactive”. It can be left empty for existing users.

temporary_access_starts – datetime. Indicates when the temporary access starts.

2. Add access field to Add/Edit pages of the login table. Set ‘Edit as’ type to ‘Lookup wizard’ and add two hardcoded values there: “temporary” and “inactive”. Now the admin can create users with temporary access and make them inactive manually.

3. Login table -> Add page -> Before Record Added event

Here we simply initialize temporary_access_starts with the value of the current date/time.

PHP code:

C# code:

4. Login Page -> BeforeLogin event

In this event we first check the value of user’s access field. If it says “inactive”, we reject the login. If it says “temporary” and the value of temporary_access_starts field is more than 24 hours old, then we also reject the login. All other users can log on.

PHP code:

C# code:

Leave a Reply

Your email address will not be published. Required fields are marked *