summaryrefslogtreecommitdiffstats
path: root/ipa-server/ipa-gui/ipagui/helpers/userhelper.py
blob: 2a2571dbe3abbb5e235836d9ec4f12e9a6370cfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sys
import datetime

from ipa import ipautil

def password_expires_in(datestr):
    """Returns the number of days that password expires in.  Returns a negative number
       if the password is already expired."""
    if (datestr == None) or (datestr == ""):
        return sys.maxint

    expdate = ipautil.parse_generalized_time(datestr)
    if not expdate:
        return sys.maxint

    delta = expdate - datetime.datetime.now()
    return delta.days

def password_is_expired(days):
    return days < 0

def password_expires_soon(days):
    return (not password_is_expired(days)) and (days < 7)