Home > Mobile >  std::time() and its dependence on daylight saving
std::time() and its dependence on daylight saving

Time:06-04

I have a requirement to lock a user, if 3 consecutive login attempts are failed within 15 minutes. I am going to check with the following formula, if third login attempt fails.

    if (first_login_attemp_time   900 <= std::time(nullptr))
    {
        lockuser();
    }

If the first login attempt fails, I set first_login_attemp_time as given below

first_login_attemp_time = std::time(nullptr)

Will this code work if daylight saving time change occurs in the 15 minutes window? Should I consider something else for day light saving?

CodePudding user response:

The std::time returns UTC time that does not follow daylight saving policies of local authorities. So about daylight savings there are no worries.

Like the cited reference article says most systems implement std::time_t (that std::time returns) as in POSIX standard. In my experience it is all systems that I know of. So it is extremely likely to be integral value in seconds and so your 900 results with its advance by 15 minutes.

However logic of your code is strange. It locks user when more than 15 minutes has passed since first attempt and that is not usually what is called "within 15 minutes".

  • Related