import base64
import random
import string
from Crypto.Cipher import AES

def get_fernet_with_key(key):
    return Fernet2(key)

def encrypt(f, msg):
    return f.encrypt(str(msg))

def decrypt(f, token):
    return f.decrypt(str(token))

def login(f, token):
    try:
        password = decrypt(f, token)
        return True, password
    except AssertionError:
        return False, None

def generate_fernet_key(pin, salt=None):
    if salt is None:
        useSalt = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(249))
    else:
        useSalt = salt

    pre_key = pin + "_" + useSalt
    key = base64.urlsafe_b64encode(pre_key)

    if salt is None:
        return key, useSalt
    else:
        return key

class Fernet2:
    key = None
    aes = None

    def __init__(self, key):
        self.key = key
        self.aes = AES.new(key, AES.MODE_ECB)

    def encrypt(self, msg):
        return self.aes.encrypt(msg + "CHECK")

    def decrypt(self, msg):
        plaintext = self.aes.decrypt(msg)
        if "CHECK" not in plaintext:
            raise AssertionError("Invalid key")
        else:
            return plaintext[:-5]
@@ -560,10 +560,9 @@
 ge(2
-49
+5
 ))%0A 

Fix crypto again (key size)