diff --git a/app.py b/app.py index 6ee8258..bf20cfd 100644 --- a/app.py +++ b/app.py @@ -47,18 +47,15 @@ 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 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}) if algorithm == 'argon2_copyparty': + + specified_salt = 'LVZ1TJMdAIdLyBla6nWDexFt' b_pass = password.encode('utf-8') - b_salt = salt.encode('utf-8') + b_salt = specified_salt.encode('utf-8') raw_hash_copyparty = hash_secret( secret = b_pass, @@ -76,7 +73,15 @@ def do_hash(): 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') diff --git a/static/css/style.css b/static/css/style.css index 693d0fd..0f6c880 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -40,6 +40,13 @@ button:hover { cursor: pointer; } +button:disabled { + background: #666666; + color: #aaaaaa; + cursor: not-allowed; + filter: grayscale(1); +} + .row { display: flex; gap: 8px diff --git a/static/js/main.js b/static/js/main.js index 81dd99e..a3b9272 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -19,6 +19,25 @@ gensaltBtn.addEventListener('click', async () => { salt.value = data.salt; }); +const updateUI = () => { + const isCopyparty = algorithm.value === 'argon2_copyparty'; + + salt.disabled = isCopyparty; + gensaltBtn.disabled = isCopyparty; + + if (isCopyparty) { + salt.value = "LVZ1TJMdAIdLyBla6nWDexFt"; + salt.style.opacity = "0.5"; + } else { + + salt.value = ""; + salt.style.opacity = ""; + } +}; + +algorithm.addEventListener('change', updateUI); +window.addEventListener('DOMContentLoaded', updateUI); + hashBtn.addEventListener('click', async () => { const pass = password.value || ''; const s = salt.value || ''; @@ -29,11 +48,14 @@ hashBtn.addEventListener('click', async () => { 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 }; const res = await fetch('/hash', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) diff --git a/templates/index.html b/templates/index.html index 84f0620..ae05303 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,7 +13,7 @@