-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
59 lines (39 loc) · 897 Bytes
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pyotp
import time
import csv
import pickle
import os
otpsfile= ".priv"
def getdata():
try:
with open(otpsfile, "rb") as myFile:
accdict = pickle.load(myFile)
return accdict
except:
accdict={}
return accdict
accdict=getdata()
def savedata():
with open(otpsfile, "wb") as myFile:
pickle.dump(accdict, myFile)
def verifyOTP(token,otp):
totp = pyotp.TOTP(token)
return totp.verify(otp) # => True
def getOTP(token):
totp = pyotp.TOTP(token)
otp = totp.now()
return otp
def addacc(accname,token):
if accname not in accdict.keys():
accdict[accname]=token
savedata()
return accname + " Added Succesfully"
else:
return "alreadyhere"
def clear():
# for mac and linux(here, os.name is 'posix')
if os.name == 'posix':
_ = os.system('clear')
else:
# for windows platfrom
_ = os.system('cls')