From 3e6a8882d7235a016877d7bfbf42345b45f0ff0f Mon Sep 17 00:00:00 2001 From: eriUNK Date: Tue, 3 Mar 2026 14:45:30 -0300 Subject: [PATCH] Modified files to accept argon2 as new option --- app.py | 17 ++++++++++++++--- templates/index.html | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index b72576e..2b2cad6 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,11 @@ from flask import Flask, request, jsonify, render_template, abort -import secrets, crypt, os +from argon2 import PasswordHasher +import secrets, os + +try: + import crypt +except ImportError: + import crypt_r as crypt app = Flask(__name__, static_folder='static', template_folder='templates') @@ -8,10 +14,12 @@ MIN_LEN = 16 MIN_SALT_LEN = 8 MAX_SALT_LEN = 16 +ph = PasswordHasher() ALG_PREFIX = { 'sha512': '$6$', 'sha256': '$5$', + 'argon2': '$argon2id$' } # The main route @@ -42,12 +50,15 @@ 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) + return jsonify({'hash': hashed}) + + prefix = ALG_PREFIX.get(algorithm) - if prefix is None: abort(400, 'Unsupported algorithm') - full_salt = f"{prefix}{salt}" hashed = crypt.crypt(password, full_salt) return jsonify({'hash': hashed}) diff --git a/templates/index.html b/templates/index.html index 1cc7ecd..bd4edd7 100644 --- a/templates/index.html +++ b/templates/index.html @@ -16,6 +16,7 @@