Added copyparty (in theory)

This commit is contained in:
eriUNK
2026-03-03 15:26:57 -03:00
parent 3e6a8882d7
commit 8338bc3b73
2 changed files with 26 additions and 4 deletions

27
app.py
View File

@@ -1,5 +1,6 @@
from flask import Flask, request, jsonify, render_template, abort
from argon2 import PasswordHasher
from argon2.low_level import Type as ArgonType, hash_secret
import secrets, os
try:
@@ -19,7 +20,8 @@ ph = PasswordHasher()
ALG_PREFIX = {
'sha512': '$6$',
'sha256': '$5$',
'argon2': '$argon2id$'
'argon2_std': '$argon2id$',
'argon2_copyparty': '+'
}
# The main route
@@ -50,10 +52,29 @@ def do_hash():
if len(salt) < MIN_SALT_LEN or len(salt) > MAX_SALT_LEN:
abort(400, f'Salt must be between {MIN_SALT_LEN} and {MAX_SALT_LEN} characters')
if algorithm == 'argon2':
hashed = ph.hash(password + salt)
if algorithm == 'argon2_std':
hashed = ph.hash(password, salt = salt.encode('utf-8'))
return jsonify({'hash': hashed})
if algorithm == 'argon2_copyparty':
b_pass = password.encode('utf-8')
b_salt = salt.encode('utf-8')
raw_hash_copyparty = hash_secret(
secret = b_pass,
salt = b_salt,
time_cost = 3,
memory_cost = 256 * 1024,
parallelism = 4,
hash_len = 24,
type = ArgonType.ID,
version = 19
)
hash_only = raw_hash_copyparty.split(b"$")[-1].decode('utf-8')
final_hash = "+" + hash_only.replace('/', "_").replace('+', '-')
return jsonify({'hash': final_hash})
prefix = ALG_PREFIX.get(algorithm)
if prefix is None: