From 1d2d027b823b264fa224718b4720be0b7e632457 Mon Sep 17 00:00:00 2001 From: protopuppy <92961116+protopuppy@users.noreply.github.com> Date: Wed, 28 Sep 2022 22:09:45 +0530 Subject: [PATCH] Create auth.py --- util/auth.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 util/auth.py diff --git a/util/auth.py b/util/auth.py new file mode 100644 index 0000000..fad2262 --- /dev/null +++ b/util/auth.py @@ -0,0 +1,37 @@ +from Crypto.PublicKey import RSA +import binascii +import random +import requests +import os + +def verfiyKey(key: str): + try: + if len(key) < 750: + return False + RSA.importKey(binascii.unhexlify(key)) + # .publickey().exportKey('PEM') + return True + except: + return False + + +# function for otp generation +def otpgen(): + otp="" + for i in range(4): + otp+=str(random.randint(1,9)) + return otp + + +def SendOtp(mail, frm): + otp=otpgen() + requests.post( + "https://api.eu.mailgun.net/v3/account.vote-chain.tech/messages", + auth=("api", os.environ.get('mailGunAPI')), + data={"from": "VoteChain verification <{}@account.vote-chain.tech>".format(frm), + "to": [mail], + "subject": "Account verification | VoteChain", + "template": "otpsend", + "v:otp":otp}) + return otp +Footer