Added a button to copy result. Plus note for password.
This commit is contained in:
1
app.py
1
app.py
@@ -56,3 +56,4 @@ if __name__ == '__main__':
|
|||||||
port = int(os.environ.get('PORT', 4444))
|
port = int(os.environ.get('PORT', 4444))
|
||||||
debug = os.environ.get('DEBUG', '1') == '1'
|
debug = os.environ.get('DEBUG', '1') == '1'
|
||||||
app.run(host=host, port=port, debug=debug)
|
app.run(host=host, port=port, debug=debug)
|
||||||
|
|
||||||
|
|||||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
@@ -5,6 +5,7 @@ const salt = document.getElementById('salt');
|
|||||||
const hashBtn = document.getElementById('hashBtn');
|
const hashBtn = document.getElementById('hashBtn');
|
||||||
const result = document.getElementById('result');
|
const result = document.getElementById('result');
|
||||||
const clearBtn = document.getElementById('clearBtn');
|
const clearBtn = document.getElementById('clearBtn');
|
||||||
|
const resultBtn = document.getElementById('resultBtn');
|
||||||
|
|
||||||
const MIN_PASS_LEN = 16;
|
const MIN_PASS_LEN = 16;
|
||||||
const MIN_SALT_LEN = 8;
|
const MIN_SALT_LEN = 8;
|
||||||
@@ -54,3 +55,15 @@ clearBtn.addEventListener('click', () => {
|
|||||||
result.value = '';
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
62
static/js/main.js.save
Normal file
62
static/js/main.js.save
Normal file
@@ -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);
|
||||||
|
});
|
||||||
@@ -4,13 +4,13 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
<title>TNC's Hashing Tool</title>
|
<title>The Night Club's Hashing Tool</title>
|
||||||
<link rel="stylesheet" href="/static/css/style.css">
|
<link rel="stylesheet" href="/static/css/style.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h2>TNC's Hashing Tool</h2>
|
<h2>The Night Club's Hashing Tool</h2>
|
||||||
|
|
||||||
<label for="algorithm">Algorithm</label>
|
<label for="algorithm">Algorithm</label>
|
||||||
<select id="algorithm">
|
<select id="algorithm">
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<label for="password">Password (minimum 16 characters)</label>
|
<label for="password">Password (you will use this to login, minimum 16 characters)</label>
|
||||||
<input id="password" type="password" placeholder="Enter password" minlength="16">
|
<input id="password" type="password" placeholder="Enter password" minlength="16">
|
||||||
|
|
||||||
|
|
||||||
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<label for="result">Result</label>
|
<label for="result">Result</label>
|
||||||
|
<button id="resultBtn" type="button">Copy result</button>
|
||||||
<textarea id="result" rows="4" readonly placeholder="Result will appear here"></textarea>
|
<textarea id="result" rows="4" readonly placeholder="Result will appear here"></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user