none
How to enforce logon hours restriction in asp.net application RRS feed

  • Question

  • Dear Friends,

    In my web application i want to implement that users should be allowed to logon only in their work time.

    Its very easy to validate in day shifts just by implementing greater/less than clause on logintime but in case of shifts where some workhours fall in next day, i am finding it difficult to implement.

    I am confused how to enforce validation in case of following shifts.

    Shift 1: 6 PM - 2 AM

    Shift 2: 10 PM - 6 AM

     

    Following is my UserTable

    UserID

    Password

    WorkStartTime (Time Data Type)

    WorkEndTime (Time Data Type)

     

    I would be thankful if somebody can suggest me the way to implement it.

     

    Thanks

    David Johnson

     


    David Johnsan - Please remember to mark the replies as answers if they help.
    Wednesday, October 6, 2010 1:44 PM

Answers

  • Hi David,

    Take a look if the following algorithm helps:

     

    function isWorkingHour(loginTime, WorkStartTime, WorkEndTime)

    {

         if (WorkStartTime <= WorkEndTime) // normal flow -> all workhours fall the same day

         {

              if (loginTime >= WorkStartTime) and (loginTime <= WorkEndTime)

              {

                    return true // login time ok

              }

              else

              {

                   return false // login time invalid

              }

         }

         else // alternate flow -> workhours falling the next day

         {

              if (loginTime < WorkStartTime) and (loginTime > WorkEndTime)

              {

                   return false // login time invalid

              }

              else

              {

                   return true // login time ok

              }

         }

    }

     

    Hope this help. Have a nice day.

    Verison.

    • Marked as answer by David Johnsan Monday, October 11, 2010 6:00 AM
    Thursday, October 7, 2010 10:29 PM

All replies

  • Hi David,

    Take a look if the following algorithm helps:

     

    function isWorkingHour(loginTime, WorkStartTime, WorkEndTime)

    {

         if (WorkStartTime <= WorkEndTime) // normal flow -> all workhours fall the same day

         {

              if (loginTime >= WorkStartTime) and (loginTime <= WorkEndTime)

              {

                    return true // login time ok

              }

              else

              {

                   return false // login time invalid

              }

         }

         else // alternate flow -> workhours falling the next day

         {

              if (loginTime < WorkStartTime) and (loginTime > WorkEndTime)

              {

                   return false // login time invalid

              }

              else

              {

                   return true // login time ok

              }

         }

    }

     

    Hope this help. Have a nice day.

    Verison.

    • Marked as answer by David Johnsan Monday, October 11, 2010 6:00 AM
    Thursday, October 7, 2010 10:29 PM
  • Hi Verison,

     

    Thanks very much for your reply. This logic works well.

     

    Regards,

    David


    David Johnsan - Please remember to mark the replies as answers if they help.
    Monday, October 11, 2010 6:00 AM