Compare commits
10 Commits
cf1ceae94c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b49c7737c0 | ||
| 072181b459 | |||
|
|
62c8da94c9 | ||
|
|
c7808614b6 | ||
|
|
ced732876f | ||
|
|
8338bc3b73 | ||
|
|
3e6a8882d7 | ||
|
|
de40a534df | ||
|
|
2c71f4f68b | ||
| d9d93d8522 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
venv/
|
||||
.venv/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
47
app.py
47
app.py
@@ -1,5 +1,12 @@
|
||||
from flask import Flask, request, jsonify, render_template, abort
|
||||
import secrets, crypt, os
|
||||
from argon2 import PasswordHasher
|
||||
from argon2.low_level import Type as ArgonType, hash_secret
|
||||
import secrets, os
|
||||
|
||||
try:
|
||||
import crypt
|
||||
except ImportError:
|
||||
import crypt_r as crypt
|
||||
|
||||
app = Flask(__name__, static_folder='static', template_folder='templates')
|
||||
|
||||
@@ -8,10 +15,13 @@ MIN_LEN = 16
|
||||
MIN_SALT_LEN = 8
|
||||
MAX_SALT_LEN = 16
|
||||
|
||||
ph = PasswordHasher()
|
||||
|
||||
ALG_PREFIX = {
|
||||
'sha512': '$6$',
|
||||
'sha256': '$5$',
|
||||
'argon2_std': '$argon2id$',
|
||||
'argon2_copyparty': '+'
|
||||
}
|
||||
|
||||
# The main route
|
||||
@@ -30,6 +40,7 @@ def gensalt():
|
||||
@app.route('/hash', methods=['POST'])
|
||||
def do_hash():
|
||||
data = request.get_json() or {}
|
||||
username = data.get('username', '')
|
||||
password = data.get('password', '')
|
||||
salt = data.get('salt', '')
|
||||
algorithm = data.get('algorithm', 'sha512')
|
||||
@@ -37,17 +48,49 @@ def do_hash():
|
||||
|
||||
if not isinstance(password, str) or not isinstance(salt, str):
|
||||
abort(400, 'Invalid input')
|
||||
|
||||
if len(password) < MIN_LEN:
|
||||
abort(400, f'Password must be at least {MIN_LEN} characters')
|
||||
|
||||
if algorithm == 'argon2_copyparty':
|
||||
if (username == '' or username == None):
|
||||
abort(400, 'Please type your username.')
|
||||
|
||||
specified_salt = 'LVZ1TJMdAIdLyBla6nWDexFt'
|
||||
|
||||
full_block = f"{username}:{password}"
|
||||
|
||||
b_pass = full_block.encode('utf-8')
|
||||
b_salt = specified_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})
|
||||
|
||||
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_std':
|
||||
hashed = ph.hash(password, salt = salt.encode('utf-8'))
|
||||
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})
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
argon2-cffi==25.1.0
|
||||
argon2-cffi-bindings==25.1.0
|
||||
blinker==1.9.0
|
||||
cffi==2.0.0
|
||||
click==8.3.0
|
||||
colorama==0.4.6
|
||||
crypt_r==3.13.1
|
||||
Flask==3.1.2
|
||||
itsdangerous==2.2.0
|
||||
Jinja2==3.1.6
|
||||
MarkupSafe==3.0.3
|
||||
passlib==1.7.4
|
||||
pycparser==3.0
|
||||
Werkzeug==3.1.3
|
||||
|
||||
@@ -40,6 +40,14 @@ button:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:disabled,
|
||||
input:disabled {
|
||||
background: #666666;
|
||||
color: #aaaaaa;
|
||||
cursor: not-allowed;
|
||||
filter: grayscale(1);
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
gap: 8px
|
||||
|
||||
@@ -6,6 +6,7 @@ const hashBtn = document.getElementById('hashBtn');
|
||||
const result = document.getElementById('result');
|
||||
const clearBtn = document.getElementById('clearBtn');
|
||||
const resultBtn = document.getElementById('resultBtn');
|
||||
const username = document.getElementById('username');
|
||||
|
||||
const MIN_PASS_LEN = 16;
|
||||
const MIN_SALT_LEN = 8;
|
||||
@@ -19,22 +20,53 @@ gensaltBtn.addEventListener('click', async () => {
|
||||
salt.value = data.salt;
|
||||
});
|
||||
|
||||
const updateUI = () => {
|
||||
const isCopyparty = algorithm.value === 'argon2_copyparty';
|
||||
|
||||
salt.disabled = isCopyparty;
|
||||
gensaltBtn.disabled = isCopyparty;
|
||||
username.disabled = !isCopyparty;
|
||||
|
||||
if (isCopyparty) {
|
||||
salt.value = "LVZ1TJMdAIdLyBla6nWDexFt";
|
||||
salt.style.opacity = "0.5";
|
||||
} else {
|
||||
salt.value = "";
|
||||
salt.style.opacity = "";
|
||||
username.value = "";
|
||||
}
|
||||
};
|
||||
|
||||
algorithm.addEventListener('change', updateUI);
|
||||
window.addEventListener('DOMContentLoaded', updateUI);
|
||||
|
||||
hashBtn.addEventListener('click', async () => {
|
||||
const pass = password.value || '';
|
||||
const s = salt.value || '';
|
||||
const alg = algorithm.value;
|
||||
const usr = username.value || '';
|
||||
|
||||
if (pass.length < MIN_PASS_LEN) {
|
||||
alert('Password must be at least ' + MIN_PASS_LEN + ' characters');
|
||||
return;
|
||||
}
|
||||
|
||||
if (s.length < MIN_SALT_LEN || s.length > MAX_SALT_LEN) {
|
||||
alert('Salt must be between ' + MIN_SALT_LEN + ' and ' + MAX_SALT_LEN + ' characters');
|
||||
return;
|
||||
if (alg !== 'argon2_copyparty') {
|
||||
if (s.length < MIN_SALT_LEN || s.length > MAX_SALT_LEN) {
|
||||
alert('Salt must be between ' + MIN_SALT_LEN + ' and ' + MAX_SALT_LEN + ' characters');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const payload = { password: pass, salt: s, algorithm: alg };
|
||||
if (alg == 'argon2_copyparty') {
|
||||
if (usr === '') {
|
||||
alert('Please type your username.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const payload = { username: usr, password: pass, salt: s, algorithm: alg };
|
||||
const res = await fetch('/hash', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload)
|
||||
});
|
||||
@@ -46,22 +78,22 @@ hashBtn.addEventListener('click', async () => {
|
||||
}
|
||||
|
||||
const data = await res.json();
|
||||
result.value = data.hash;
|
||||
result.textContent = data.hash;
|
||||
});
|
||||
|
||||
clearBtn.addEventListener('click', () => {
|
||||
password.value = '';
|
||||
salt.value = '';
|
||||
result.value = '';
|
||||
result.textContent = 'Result will appear here';
|
||||
});
|
||||
|
||||
resultBtn.addEventListener('click', async () => {
|
||||
if (!result.value) {
|
||||
if (!result.textContent || result.textContent === 'Result will appear here') {
|
||||
alert('Nothing to copy.');
|
||||
}
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(result.value);
|
||||
await navigator.clipboard.writeText(result.textContent);
|
||||
alert('Copied to clipboard.');
|
||||
} catch (err) {
|
||||
alert('Failed to copy: ' + err);
|
||||
|
||||
@@ -13,9 +13,11 @@
|
||||
<h2>The Night Club's Hashing Tool</h2>
|
||||
|
||||
<label for="algorithm">Algorithm</label>
|
||||
<select id="algorithm">
|
||||
<select id="algorithm" onchange="updateUI()">
|
||||
<option value="sha512">sha512-crypt ($6$)</option>
|
||||
<option value="sha256">sha256-crypt ($5$)</option>
|
||||
<option value="argon2_std">argon2 ($argon2id$)</option>
|
||||
<option value="argon2_copyparty">argon2 (copyparty)</option>
|
||||
</select>
|
||||
|
||||
|
||||
@@ -30,6 +32,8 @@
|
||||
</div>
|
||||
<div class="note">Salt characters limited to <code>./0-9A-Za-z</code>.</div>
|
||||
|
||||
<label for="username">Username (copyparty only)</label>
|
||||
<input id="username" type="text" placeholder="Enter username">
|
||||
|
||||
<div class="controls">
|
||||
<button id="hashBtn">Compute hash</button>
|
||||
@@ -37,9 +41,9 @@
|
||||
</div>
|
||||
|
||||
|
||||
<label for="result">Result</label>
|
||||
<label>Result</label>
|
||||
<pre id="result" class="result-box">Result will appear here</pre>
|
||||
<button id="resultBtn" type="button">Copy result</button>
|
||||
<textarea id="result" rows="4" readonly placeholder="Result will appear here"></textarea>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/main.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user