Modified files to accept argon2 as new option
This commit is contained in:
17
app.py
17
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')
|
||||
|
||||
prefix = ALG_PREFIX.get(algorithm)
|
||||
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})
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<select id="algorithm">
|
||||
<option value="sha512">sha512-crypt ($6$)</option>
|
||||
<option value="sha256">sha256-crypt ($5$)</option>
|
||||
<option value="argon2">argon2 ($argon2id$)</option>
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user