Add user tripcodes
Users can separate their name and a password with ## to create the illusion of consistent posting. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
from django.utils import timezone
|
||||
from django.conf import settings
|
||||
import base64
|
||||
import hashlib
|
||||
import ipaddress
|
||||
import random
|
||||
import string
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
|
||||
from django.utils import timezone
|
||||
from django.conf import settings
|
||||
|
||||
from board.models import Ban, RangeBan
|
||||
|
||||
@@ -56,3 +59,11 @@ def generate_user_token() -> str:
|
||||
User tokens need not be secure so this is a simple implementation.
|
||||
"""
|
||||
return "".join(random.choices(string.ascii_letters, k=settings.USER_TOKEN_LENGTH))
|
||||
|
||||
|
||||
def generate_tripcode(value: str) -> str:
|
||||
hasher = hashlib.sha256()
|
||||
hasher.update(settings.TRIPCODE_SALT.encode())
|
||||
hasher.update(value.encode())
|
||||
trip = base64.b64encode(hasher.digest()).decode("ascii")
|
||||
return trip[0:10]
|
||||
|
||||
Reference in New Issue
Block a user