def test_hotp(): print "\n1.a test hotp" auth = OtpAuth('python') code = auth.hotp() assert auth.valid_hotp(code) print "secret <%s> code <%s>" % (auth.secret, code) #print dir(auth) print "completed successfully"
def test_hotp(): auth = OtpAuth('python') code = auth.hotp(4) assert auth.valid_hotp(code) == 4 # false assert auth.valid_hotp(1234567) is False assert auth.valid_hotp(123456) is False assert auth.valid_hotp('123456') is False
def qrCoderValid(inputStr): auth = OtpAuth(inputStr) hotp_code = auth.hotp(6) valid = auth.valid_hotp(hotp_code) # hotp_code = auth.hotp(6) # valid = auth.valid_hotp(hotp_code) totp_code = auth.totp(period=30, ) print(totp_code) if auth.valid_totp(totp_code): return totp_code return totp_code
def segundo_fator(self, metodo, chave): """ Calcula e retorna one-time passwords para uso como segundo fator de autenticação baseados em tempo ou hashes criptografados. ARGS: - metodo (string): pode ser 'time' ou 'hmac'. - chave (string): a chave privada usada para gerar os códigos. """ au = OtpAuth(chave) if metodo == 'time': return au.totp() elif metodo == 'hmac': return au.hotp() else: raise ValueError('método não identificado')
import sys import math from otpauth import OtpAuth count=5 val="kaow" auth = OtpAuth(val) res= auth.hotp(count) print(auth) print (("Hashed OTP is: "+str(res))) print ("Authenication is: ",str(auth.valid_hotp(res))) res=auth.totp() print ("Time based OTP: ",str(res)) print ("Valid TOTP: ",str(auth.valid_totp(res))) print ("Begin of Python Script\n") print ("The passed arguments are ", sys.argv) print ("Show all argument") for i in range(len(sys.argv)): print ("sys.argv["+str(i)+"] => "+str(sys.argv[i]))
def generate_otp(time): auth = OtpAuth('najvj5u2sd5svty') # a secret string token = format(auth.hotp(time), '06') return token