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
|
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')
|
app = Flask(__name__, static_folder='static', template_folder='templates')
|
||||||
|
|
||||||
@@ -8,10 +14,12 @@ MIN_LEN = 16
|
|||||||
MIN_SALT_LEN = 8
|
MIN_SALT_LEN = 8
|
||||||
MAX_SALT_LEN = 16
|
MAX_SALT_LEN = 16
|
||||||
|
|
||||||
|
ph = PasswordHasher()
|
||||||
|
|
||||||
ALG_PREFIX = {
|
ALG_PREFIX = {
|
||||||
'sha512': '$6$',
|
'sha512': '$6$',
|
||||||
'sha256': '$5$',
|
'sha256': '$5$',
|
||||||
|
'argon2': '$argon2id$'
|
||||||
}
|
}
|
||||||
|
|
||||||
# The main route
|
# The main route
|
||||||
@@ -42,12 +50,15 @@ def do_hash():
|
|||||||
if len(salt) < MIN_SALT_LEN or len(salt) > MAX_SALT_LEN:
|
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')
|
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)
|
prefix = ALG_PREFIX.get(algorithm)
|
||||||
|
|
||||||
if prefix is None:
|
if prefix is None:
|
||||||
abort(400, 'Unsupported algorithm')
|
abort(400, 'Unsupported algorithm')
|
||||||
|
|
||||||
|
|
||||||
full_salt = f"{prefix}{salt}"
|
full_salt = f"{prefix}{salt}"
|
||||||
hashed = crypt.crypt(password, full_salt)
|
hashed = crypt.crypt(password, full_salt)
|
||||||
return jsonify({'hash': hashed})
|
return jsonify({'hash': hashed})
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
<select id="algorithm">
|
<select id="algorithm">
|
||||||
<option value="sha512">sha512-crypt ($6$)</option>
|
<option value="sha512">sha512-crypt ($6$)</option>
|
||||||
<option value="sha256">sha256-crypt ($5$)</option>
|
<option value="sha256">sha256-crypt ($5$)</option>
|
||||||
|
<option value="argon2">argon2 ($argon2id$)</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user