· 5 years ago · Aug 07, 2020, 06:12 PM
1import hashlib as crypto
2
3_secretKey = "SECRET_KEY"
4
5
6def generateOTP(email):
7 otp = "123456" # Static OTP For Testing Purposes
8
9 # sendOTP(otp,email) // send the OTP to the given email address
10
11 payload = email + otp + _secretKey
12
13 res = crypto.sha256(payload.encode())
14 print(res.hexdigest()) # Send this Resilt back to USER
15
16
17def verifyOTP(otp, email, hash):
18 payload = email + otp + _secretKey # generate payload to compare with hash
19 res = crypto.sha256(payload.encode())
20 print(res)
21 if(hash == res.hexdigest()):
22 print("Verified")
23 else:
24 print("Wrong Otp")
25
26generateOTP("test@test.com")
27verifyOTP("123456","test@test.com","d0b4b5c40202a99ef04cf2ab5342fa95c9eb922af92184412150e6a21bd9d4e5")