def VerifyOTP(user, otp):
 timestamp = long(time.time())
 challenge = (timestamp / _GRANULARITY)
 units = (_TIMEOUT / _GRANULARITY)
 secret = _GetUserSecret(user)
 ts = _UpdateUserHistory(user, timestamp, otp)
 if ((len(ts) - bisect.bisect_left(ts, ((timestamp - 60),))) > _ATTEMPTS_PER_MIN):
  raise OTPException('Too many OTP login attempts for {0} in past minute'.format(user))
 if [True for x in ts[:(-1)] if (x[1] == otp)]:
  raise OTPException('Have already seen OTP {0} for {1}'.format(otp, user))
 for offset in range(((- (units - 1)) / 2), ((units / 2) + 1)):
  if (int(otp) == _ComputeOTP(secret, (challenge + offset))):
   return
 raise OTPException('Entered OTP invalid')

def VerifyOTP ( user , otp ) : timestamp = long ( time . time ( ) ) challenge = ( timestamp / _GRANULARITY ) units = ( _TIMEOUT / _GRANULARITY ) secret = _GetUserSecret ( user ) ts = _UpdateUserHistory ( user , timestamp , otp ) if ( ( len ( ts ) - bisect . bisect_left ( ts , ( ( timestamp - 60 ) , ) ) ) > _ATTEMPTS_PER_MIN ) : raise OTPException ( 'Too many OTP login attempts for {0} in past minute' . format ( user ) ) if [ True for x in ts [ : ( - 1 ) ] if ( x [ 1 ] == otp ) ] : raise OTPException ( 'Have already seen OTP {0} for {1}' . format ( otp , user ) ) for offset in range ( ( ( - ( units - 1 ) ) / 2 ) , ( ( units / 2 ) + 1 ) ) : if ( int ( otp ) == _ComputeOTP ( secret , ( challenge + offset ) ) ) : return raise OTPException ( 'Entered OTP invalid' )
verifies the provided otp for the user by comparing it to one generated right now .