'check if user is logging in during restricted hours'

def validate_hour(self):

    login_before = int((frappe.db.get_value(u'User', self.user, u'login_before', ignore=True) or 0))
    login_after = int((frappe.db.get_value(u'User', self.user, u'login_after', ignore=True) or 0))
    if (not (login_before or login_after)):
        return
    from frappe.utils import now_datetime
    current_hour = int(now_datetime().strftime(u'%H'))
    if (login_before and (current_hour > login_before)):
        frappe.throw(_(u'Login    not    allowed    at    this    time'), frappe.AuthenticationError)
    if (login_after and (current_hour < login_after)):
        frappe.throw(_(u'Login    not    allowed    at    this    time'), frappe.AuthenticationError)
