From af7fa0b87ec5fa2d58bbc32361f12b329e41dd01 Mon Sep 17 00:00:00 2001 From: Eri Date: Mon, 19 Jan 2026 16:47:13 +0100 Subject: [PATCH] Added a button to copy result. Plus note for password. --- app.py | 1 + requirements.txt | Bin 300 -> 140 bytes static/js/main.js | 13 +++++++++ static/js/main.js.save | 62 +++++++++++++++++++++++++++++++++++++++++ templates/index.html | 7 +++-- 5 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 static/js/main.js.save diff --git a/app.py b/app.py index 7c1dffb..d7cbace 100644 --- a/app.py +++ b/app.py @@ -56,3 +56,4 @@ if __name__ == '__main__': port = int(os.environ.get('PORT', 4444)) debug = os.environ.get('DEBUG', '1') == '1' app.run(host=host, port=port, debug=debug) + diff --git a/requirements.txt b/requirements.txt index ca84604449f8748a218a746e82af9f3fdc1f034a..7acc7400f6156fe7fde7e39275420e46920de5f2 100644 GIT binary patch literal 140 zcmXAiu@1s83`BQ-jFl!;fx#;S5>p3ex0os0u>&RByd$%(wf z)wX*CR;1#rD|sl);f { result.value = ''; }); +resultBtn.addEventListener('click', async () => { + if (!result.value) { + alert('Nothing to copy.'); + } + + try { + await navigator.clipboard.writeText(result.value); + alert('Copied to clipboard.'); + } catch (err) { + alert('Failed to copy: ' + err); + } +}); diff --git a/static/js/main.js.save b/static/js/main.js.save new file mode 100644 index 0000000..7000320 --- /dev/null +++ b/static/js/main.js.save @@ -0,0 +1,62 @@ +const gensaltBtn = document.getElementById('gensaltBtn'); +const algorithm = document.getElementById('algorithm'); +const password = document.getElementById('password'); +const salt = document.getElementById('salt'); +const hashBtn = document.getElementById('hashBtn'); +const result = document.getElementById('result'); +const clearBtn = document.getElementById('clearBtn'); +const resultBtn = document.getElementById('resultBtn'); + +const MIN_PASS_LEN = 16; +const MIN_SALT_LEN = 8; +const MAX_SALT_LEN = 16; + +gensaltBtn.addEventListener('click', async () => { + const len = MAX_SALT_LEN; // can be adjusted or user-defined + const res = await fetch('/gensalt?length=' + len); + if (!res.ok) { alert('Could not generate salt'); return; } + const data = await res.json(); + salt.value = data.salt; +}); + +hashBtn.addEventListener('click', async () => { + const pass = password.value || ''; + const s = salt.value || ''; + const alg = algorithm.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; + } + + const payload = { password: pass, salt: s, algorithm: alg }; + const res = await fetch('/hash', { + method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) + }); + + if (!res.ok) { + const txt = await res.text(); + alert('Error: ' + txt); + return; + } + + const data = await res.json(); + result.value = data.hash; +}); + +clearBtn.addEventListener('click', () => { + password.value = ''; + salt.value = ''; + result.value = ''; +}); + +btnResult.addEventListener('click', () => { + navigator.clipboard.writeText(result.value); + + alert("Copied text: " + result.value); +}); diff --git a/templates/index.html b/templates/index.html index 600408c..bd160d9 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,13 +4,13 @@ - TNC's Hashing Tool + The Night Club's Hashing Tool
-

TNC's Hashing Tool

+

The Night Club's Hashing Tool

- + @@ -38,6 +38,7 @@ +