Added the token generator
This commit is contained in:
+15
-4
@@ -1,8 +1,19 @@
|
||||
#from tiny0.models import URL
|
||||
from tiny0.models import URL
|
||||
from secrets import choice
|
||||
|
||||
'''
|
||||
# The characters used to generate the token
|
||||
token_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz_-"
|
||||
|
||||
Generate valid token
|
||||
def gen_valid_token():
|
||||
while True:
|
||||
# Generate a token
|
||||
token = "".join(choice(token_characters) for i in range(8))
|
||||
|
||||
# If the token does not exists in the database
|
||||
if not URL.query.filter_by(token=token).first():
|
||||
# Break the loop
|
||||
break
|
||||
|
||||
# Return the token
|
||||
return token
|
||||
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user