def get_code(secret): secret = base64.b32decode(b32pad(secret.upper())) auth = OtpAuth(secret) # a secret string code = auth.totp() # generate a time based code code = str(code).zfill(6) return code
def test_totp(): auth = OtpAuth('python') code = auth.totp() assert auth.valid_totp(code) # false assert auth.valid_totp(1234567) is False assert auth.valid_totp(123456) is False
def test_totp(): print "\n1.b test totp" auth = OtpAuth('python') code = auth.totp() assert auth.valid_totp(code) print "secret <%s> code <%s>" % (auth.secret, code) #print dir(auth) print "completed successfully"
def otpauth_totp(f_key): print "\n1.b test totp" auth = OtpAuth(f_key) # default step=30 code = auth.totp() assert auth.valid_totp(code) print "secret <%s> code <%s>" % (auth.secret, code) #print dir(auth) print "completed successfully"
def test_totp(): print "\n1.b test totp" secret= 'dev_annie_04' auth = OtpAuth(secret) code = auth.totp() assert auth.valid_totp(code) print "secret <%s> code <%s>" % (auth.secret, code) #print dir(auth) print "completed successfully"
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')
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')
def gen_TOTP(rand_text): token = bool(1) auth = OtpAuth(rand_text) print("Ref creating main is : " + rand_text) ref_totp = auth.totp() str_totp = "" if (ref_totp > 99999): str_totp = str(ref_totp) if (99999 >= ref_totp > 9999): str_totp = "0" + str(ref_totp) if (9999 >= ref_totp > 999): str_totp = "00" + str(ref_totp) if (999 >= ref_totp > 99): str_totp = "000" + str(ref_totp) if (99 >= ref_totp > 9): str_totp = "0000" + str(ref_totp) if (9 >= ref_totp): str_totp = "00000" + str(ref_totp) print("TOTP : ", str_totp) return 0
def login(): if request.method == 'POST': print 'Username: '******'Username'] print 'Password: '******'Password'] print 'Google Auth Code: ', request.form['GoogleAuth'] # Connect to database and query for user&password db = sqlite3.connect('google_authenticator.db') cursor = db.cursor() cursor.execute('SELECT GOOGLEAUTH FROM USERS WHERE USER=\'' + request.form['Username'] + '\' AND PASSWORD=\'' + request.form['Password'] + '\';') secret = cursor.fetchone() db.close() # Query returns None if user&password don't exist if secret is None: return "Unsuccesful login attempt." # Verify google authentication code with secret from database else: # Generate the otpauth protocal string. secret = secret[0] print 'Secret: ', secret auth = OtpAuth(secret) secret_uri = auth.to_uri('totp', GALabel, GAIssuer) # algorithm type, label, issuer # Generate TOTP code given code uri code = auth.totp() # Generate time based code print 'Code Uri: ', secret_uri print 'Valid Google Auth Code: ', code # Compare code provided by user with valid code if auth.valid_totp(int(request.form['GoogleAuth'])): return "Successfully logged in!" else: print "Invalid Google Authenticator." return "Unsuccessful login attempt." return "Unsuccessful login attempt." return "Nothing to see here."
def post(self, client_id, user_id): args = self.parser.parse_args() if args.secret_key != db.hget("apps:" + client_id, "secret_key"): abort(401) app_name = db.hget("apps:" + client_id, "name") user = db.hgetall( "apps:{}:users:{}".format(client_id, user_id), ) auth = OtpAuth(args.secret_key) code = auth.totp() res = requests.post( CHIKKA_SMS_ENDPOINT, data=dict( message_type="SEND", # Inconsistent mobile_number=user["number"], shortcode=current_app.config["CHIKKA_SHORTCODE"], message_id=simpleflake(), message="""{} Code: {} - """.format(app_name, code), request_cost="FREE", client_id=current_app.config["CHIKKA_CLIENT_ID"], secret_key=current_app.config["CHIKKA_SECRET_KEY"], ), ) if res.status_code != requests.codes.ok: abort(500) return ""
#!/usr/bin/env python from otpauth import OtpAuth import time, base64 secret = "QDQQFZ6AUZQ2YR6N" # key for gooby:1 auth = OtpAuth(base64.b32decode(secret)) print "[+]User: gooby, password:1" print "[+]TOTP token: [%d]" % auth.totp() print "[+]%s " % time.strftime("%c")
def otpauth_totp(f_key): print "\ntotp per raw secret" auth = OtpAuth(f_key) # default step=30 code = auth.totp() assert auth.valid_totp(code) print "secret <%s> code <%s>" % (auth.secret, code)
def _create_otp_secret(): otp_secret = OtpAuth(base64.b32encode(os.urandom(10)).decode('utf-8')) return otp_secret.totp()
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]))
''' // // nemo2 connect api // wscat --connect ws://54.215.201.239:8081/5d86cc5c-6d4b-4bf8-f8bd-a6963b279fb1/026283/event // ''' host='54.215.201.239' port='8081' dev_uuid='49ff3cdf-1a08-4541-9fb4-8c82f4e343c5' app_uuid='c1838690-6ec1-49d5-edd3-32da0b8114b4' from otpauth import OtpAuth app_key="This is interesting What is going on Need a long sentence carry on and take more" auth = OtpAuth(app_key) app_token = auth.totp() exchange='event' url ='ws://' + host + ':' + port + '/' + app_uuid +'/' + str(app_token) + '/' + exchange import json d1='{".insert":{"binding":"cloud.' + dev_uuid + '.device.ip.*.temperature"}}' d2 = json.loads(d1) data = json.dumps(d2) ''' // // main // WebSocket = require('ws')
def _create_otp_secret(): otp_secret = OtpAuth(base64.b32encode(os.urandom(10)).decode('utf-8')) return otp_secret.totp()
#!/usr/bin/env python from otpauth import OtpAuth import time, base64 secret = "QDQQFZ6AUZQ2YR6N" # key for gooby:1 auth = OtpAuth(base64.b32decode(secret)) print "[+]User: gooby, password:1" print "[+]TOTP token: [%d]" % auth.totp() print "[+]%s " % time.strftime("%c")
def otp(): auth = OtpAuth(val) res = auth.totp() return res
import socket from otpauth import OtpAuth auth = OtpAuth('secret') UDP_IP = "127.0.0.1" UDP_PORT = 5005 print "UDP target IP:", UDP_IP print "UDP target port:", UDP_PORT MESSAGE = str(auth.totp()) sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
def verify_qr(self): id = str(self.id) auth = OtpAuth(app.config['SECRET_KEY'] + id) # a secret string return auth.totp()