def check_password_expired(user):
 if (not settings.ACCOUNT_PASSWORD_USE_HISTORY):
  return False
 if hasattr(user, u'password_expiry'):
  expiry = user.password_expiry.expiry
 else:
  expiry = settings.ACCOUNT_PASSWORD_EXPIRY
 if (expiry == 0):
  return False
 try:
  latest = user.password_history.latest(u'timestamp')
 except PasswordHistory.DoesNotExist:
  return False
 now = datetime.datetime.now(tz=pytz.UTC)
 expiration = (latest.timestamp + datetime.timedelta(seconds=expiry))
 if (expiration < now):
  return True
 else:
  return False

def check_password_expired ( user ) : if ( not settings . ACCOUNT_PASSWORD_USE_HISTORY ) : return False if hasattr ( user , u'password_expiry' ) : expiry = user . password_expiry . expiry else : expiry = settings . ACCOUNT_PASSWORD_EXPIRY if ( expiry == 0 ) : return False try : latest = user . password_history . latest ( u'timestamp' ) except PasswordHistory . DoesNotExist : return False now = datetime . datetime . now ( tz = pytz . UTC ) expiration = ( latest . timestamp + datetime . timedelta ( seconds = expiry ) ) if ( expiration < now ) : return True else : return False
return true if password is expired and system is using password expiration .