reborked the token system

This commit is contained in:
Ville Rantanen
2018-03-01 15:05:29 +02:00
parent 9ed8c18fb3
commit 06d42ee956
4 changed files with 241 additions and 152 deletions

View File

@@ -1,3 +1,5 @@
import random
import string
import base64
from Crypto.Cipher import AES
import hashlib
@@ -44,6 +46,12 @@ def get_direct_token(share, filename):
)
def has_token(token, share):
if not 'tokens' in share:
return False
return token in share['tokens']
def password_hash(string, salt=""):
if type(string) == str:
string = string.encode("utf-8")
@@ -54,6 +62,12 @@ def password_hash(string, salt=""):
).hexdigest()
def random_token():
chars = [random.choice(string.ascii_letters + string.digits) for n in range(30)]
token = "".join(chars)
return token
def remove_pad(string):
""" Remove spaces from right """
return string.rstrip(" ")