本文整理汇总了Python中linotp.lib.tokens.hmactoken.HmacTokenClass.checkOtp方法的典型用法代码示例。如果您正苦于以下问题:Python HmacTokenClass.checkOtp方法的具体用法?Python HmacTokenClass.checkOtp怎么用?Python HmacTokenClass.checkOtp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linotp.lib.tokens.hmactoken.HmacTokenClass
的用法示例。
在下文中一共展示了HmacTokenClass.checkOtp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkOtp
# 需要导入模块: from linotp.lib.tokens.hmactoken import HmacTokenClass [as 别名]
# 或者: from linotp.lib.tokens.hmactoken.HmacTokenClass import checkOtp [as 别名]
def checkOtp(self, anOtpVal, counter, window, options=None):
'''
checkOtp - check the otpval of a token against a given counter
in the + window range
:param passw: the to be verified passw/pin
:type passw: string
:return: counter if found, -1 if not found
:rtype: int
'''
log.debug("[checkOtp] begin. start to verify the otp value: anOtpVal:"
" %r, counter: %r, window: %r, options: %r "
% (anOtpVal, counter, window, options))
if not options:
options = {}
ret = HmacTokenClass.checkOtp(self, anOtpVal, counter, window)
if ret != -1:
if self.isValid() == False:
ret = -1
if ret >= 0:
if get_auth_AutoSMSPolicy():
user = None
message = "<otp>"
realms = self.getRealms()
if realms:
_sms_ret, message = get_auth_smstext(realm=realms[0])
if 'user' in options:
user = options.get('user', None)
if user:
_sms_ret, message = get_auth_smstext(realm=user.realm)
realms = self.getRealms()
if 'data' in options or 'message' in options:
message = options.get('data',
options.get('message', '<otp>'))
try:
_success, message = self.sendSMS(message=message)
except Exception as exx:
log.exception(exx)
finally:
self.incOtpCounter(ret, reset=False)
if ret >= 0:
msg = "otp verification was successful!"
else:
msg = "otp verification failed!"
log.debug("[checkOtp] end. %s ret: %r" % (msg, ret))
return ret
示例2: checkOtp
# 需要导入模块: from linotp.lib.tokens.hmactoken import HmacTokenClass [as 别名]
# 或者: from linotp.lib.tokens.hmactoken.HmacTokenClass import checkOtp [as 别名]
def checkOtp(self, anOtpVal, counter, window, options=None):
"""
checkOtp - check the otpval of a token against a given counter
in the + window range
:param passw: the to be verified passw/pin
:type passw: string
:return: counter if found, -1 if not found
:rtype: int
"""
log.debug(
"[checkOtp] begin. start to verify the otp value: anOtpVal:"
+ " %r, counter: %r, window: %r, options: %r " % (anOtpVal, counter, window, options)
)
ret = HmacTokenClass.checkOtp(self, anOtpVal, counter, window)
if ret != -1:
if self.isValid() == False:
ret = -1
if ret >= 0:
if get_auth_AutoSMSPolicy():
user = None
message = "<otp>"
if options is not None and type(options) == dict:
user = options.get("user", None)
if user:
sms_ret, message = get_auth_smstext(realm=user.realm)
self.incOtpCounter(ret, reset=False)
success, message = self.sendSMS(message=message)
if ret >= 0:
msg = "otp verification was successful!"
else:
msg = "otp verification failed!"
log.debug("[checkOtp] end. %s ret: %r" % (msg, ret))
return ret