Added copyparty (in theory)
This commit is contained in:
27
app.py
27
app.py
@@ -1,5 +1,6 @@
|
|||||||
from flask import Flask, request, jsonify, render_template, abort
|
from flask import Flask, request, jsonify, render_template, abort
|
||||||
from argon2 import PasswordHasher
|
from argon2 import PasswordHasher
|
||||||
|
from argon2.low_level import Type as ArgonType, hash_secret
|
||||||
import secrets, os
|
import secrets, os
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -19,7 +20,8 @@ ph = PasswordHasher()
|
|||||||
ALG_PREFIX = {
|
ALG_PREFIX = {
|
||||||
'sha512': '$6$',
|
'sha512': '$6$',
|
||||||
'sha256': '$5$',
|
'sha256': '$5$',
|
||||||
'argon2': '$argon2id$'
|
'argon2_std': '$argon2id$',
|
||||||
|
'argon2_copyparty': '+'
|
||||||
}
|
}
|
||||||
|
|
||||||
# The main route
|
# The main route
|
||||||
@@ -50,10 +52,29 @@ 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':
|
if algorithm == 'argon2_std':
|
||||||
hashed = ph.hash(password + salt)
|
hashed = ph.hash(password, salt = salt.encode('utf-8'))
|
||||||
return jsonify({'hash': hashed})
|
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)
|
prefix = ALG_PREFIX.get(algorithm)
|
||||||
if prefix is None:
|
if prefix is None:
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
<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>
|
<option value="argon2_std">argon2 ($argon2id$)</option>
|
||||||
|
<option value="argon2_copyparty">argon2 (copyparty)</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user