-
-
+
+
+
+
+
+ First login — default credentials have been generated.
+ User: neurosploit · Password: check .env
-
@@ -225,109 +362,237 @@ html,body{height:100%;font-family:'Inter',system-ui,sans-serif;background:var(--
(function() {
'use strict';
- const form = document.getElementById('loginForm');
- const btn = document.getElementById('btnLogin');
- const errorBox = document.getElementById('errorBox');
- const errorText = document.getElementById('errorText');
- const togglePw = document.getElementById('togglePw');
- const pwInput = document.getElementById('password');
+ /* ── elements ── */
+ var loginForm = document.getElementById('loginForm');
+ var regForm = document.getElementById('regForm');
+ var btnLogin = document.getElementById('btnLogin');
+ var btnRegister = document.getElementById('btnRegister');
+ var loginError = document.getElementById('loginError');
+ var loginErrorText = document.getElementById('loginErrorText');
+ var regError = document.getElementById('regError');
+ var regErrorText = document.getElementById('regErrorText');
+ var regSuccess = document.getElementById('regSuccess');
+ var panelLogin = document.getElementById('panelLogin');
+ var panelRegister = document.getElementById('panelRegister');
+ var card = document.getElementById('card');
+ var genPwText = document.getElementById('genPwText');
- // Check if already authenticated
- const token = localStorage.getItem('ns-token');
- if (token) {
- fetch('/api/auth/verify', {
- headers: { 'Authorization': 'Bearer ' + token }
- }).then(r => { if (r.ok) window.location.href = '/'; });
+ /* ── typing animation ── */
+ var tagline = document.getElementById('tagline');
+ var text = 'AUTONOMOUS PENETRATION TESTING ENGINE';
+ var i = 0;
+ function typeChar() {
+ if (i < text.length) {
+ tagline.textContent = text.slice(0, i + 1);
+ var cursor = document.createElement('span');
+ cursor.className = 'cursor-blink';
+ tagline.appendChild(cursor);
+ i++;
+ setTimeout(typeChar, 50 + Math.random() * 40);
+ }
}
+ setTimeout(typeChar, 600);
- // Check if first login (default creds active)
- fetch('/api/auth/status').then(r => r.json()).then(data => {
- if (data.first_login) document.getElementById('firstLogin').classList.add('show');
- }).catch(() => {});
+ /* ── password generator ── */
+ function generatePassword() {
+ var chars = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
+ var special = '!@#$%&*-_=+?';
+ var pw = '';
+ var arr = new Uint8Array(24);
+ crypto.getRandomValues(arr);
+ for (var j = 0; j < 20; j++) {
+ pw += (j === 5 || j === 10 || j === 15) ? special[arr[j] % special.length] : chars[arr[j] % chars.length];
+ }
+ return pw;
+ }
+ var currentGenPw = generatePassword();
+ genPwText.textContent = currentGenPw;
- // Toggle password visibility
- togglePw.addEventListener('click', function() {
- const show = pwInput.type === 'password';
- pwInput.type = show ? 'text' : 'password';
- this.title = show ? 'Hide password' : 'Show password';
- this.innerHTML = show
- ? '
'
- : '
';
+ document.getElementById('regenPw').addEventListener('click', function() {
+ currentGenPw = generatePassword();
+ genPwText.textContent = currentGenPw;
});
- // Rate limiting
- let attempts = 0;
- let lockUntil = 0;
+ document.getElementById('copyPw').addEventListener('click', function() {
+ var btn = this;
+ navigator.clipboard.writeText(currentGenPw).then(function() {
+ btn.textContent = 'Copied!';
+ btn.classList.add('copied');
+ setTimeout(function() { btn.textContent = 'Copy'; btn.classList.remove('copied'); }, 2000);
+ });
+ });
- form.addEventListener('submit', async function(e) {
+ /* ── password strength ── */
+ var regPassConfirm = document.getElementById('regPassConfirm');
+ regPassConfirm.addEventListener('input', function() {
+ var pw = this.value;
+ var score = 0;
+ if (pw.length >= 8) score++;
+ if (pw.length >= 14) score++;
+ if (/[A-Z]/.test(pw) && /[a-z]/.test(pw)) score++;
+ if (/[0-9]/.test(pw) && /[^a-zA-Z0-9]/.test(pw)) score++;
+ var bars = document.querySelectorAll('#pwStrength .bar');
+ for (var b = 0; b < bars.length; b++) {
+ bars[b].className = 'bar';
+ if (b < score) bars[b].classList.add(score <= 1 ? 'weak' : score <= 2 ? 'medium' : 'strong');
+ }
+ });
+
+ /* ── panel switching ── */
+ document.getElementById('goRegister').addEventListener('click', function() {
+ panelLogin.classList.remove('active');
+ panelRegister.classList.add('active');
+ hideAlerts();
+ });
+ document.getElementById('goLogin').addEventListener('click', function() {
+ panelRegister.classList.remove('active');
+ panelLogin.classList.add('active');
+ hideAlerts();
+ });
+
+ /* ── toggle password visibility ── */
+ document.querySelectorAll('.toggle-pw').forEach(function(btn) {
+ btn.addEventListener('click', function() {
+ var target = document.getElementById(this.dataset.target);
+ var show = target.type === 'password';
+ target.type = show ? 'text' : 'password';
+ this.setAttribute('aria-label', show ? 'Hide password' : 'Show password');
+ this.innerHTML = show
+ ? '
'
+ : '
';
+ });
+ });
+
+ /* ── helpers ── */
+ function hideAlerts() {
+ [loginError, regError, regSuccess, document.getElementById('firstLoginBanner')].forEach(function(el) {
+ el.classList.remove('show');
+ });
+ }
+ function showAlert(el, msg, textEl) {
+ if (textEl) textEl.textContent = msg;
+ el.classList.add('show');
+ el.style.animation = 'none';
+ el.offsetHeight;
+ el.style.animation = el.classList.contains('alert-error') ? 'shake .4s ease' : '';
+ }
+
+ /* ── rate limiting ── */
+ var attempts = 0;
+ var lockUntil = 0;
+
+ /* ── check existing session ── */
+ var token = localStorage.getItem('ns_token');
+ if (token) {
+ fetch('/api/auth/verify', { headers: { 'Authorization': 'Bearer ' + token } })
+ .then(function(r) { if (r.ok) window.location.href = '/'; });
+ }
+
+ /* ── check if first login ── */
+ fetch('/api/auth/status').then(function(r) { return r.json(); }).then(function(data) {
+ if (data.first_login) {
+ document.getElementById('firstLoginBanner').classList.add('show');
+ }
+ if (data.no_users) {
+ panelLogin.classList.remove('active');
+ panelRegister.classList.add('active');
+ }
+ }).catch(function() {});
+
+ /* ── login ── */
+ loginForm.addEventListener('submit', function(e) {
e.preventDefault();
- errorBox.classList.remove('show');
+ hideAlerts();
- // Client-side rate limit
if (Date.now() < lockUntil) {
- const secs = Math.ceil((lockUntil - Date.now()) / 1000);
- showError('Too many attempts. Try again in ' + secs + 's');
+ var secs = Math.ceil((lockUntil - Date.now()) / 1000);
+ showAlert(loginError, 'Too many attempts. Try again in ' + secs + 's', loginErrorText);
return;
}
- const user = document.getElementById('username').value.trim();
- const pass = document.getElementById('password').value;
- if (!user || !pass) { showError('Please fill in both fields'); return; }
+ var user = document.getElementById('loginUser').value.trim();
+ var pass = document.getElementById('loginPass').value;
+ if (!user || !pass) { showAlert(loginError, 'Please fill in both fields', loginErrorText); return; }
- btn.classList.add('loading');
- btn.disabled = true;
+ btnLogin.classList.add('loading');
+ btnLogin.disabled = true;
- try {
- const res = await fetch('/api/auth/login', {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ username: user, password: pass })
- });
- const data = await res.json();
-
- if (res.ok && data.token) {
- localStorage.setItem('ns_token', data.token);
- // Smooth transition
- document.querySelector('.card').style.transform = 'scale(0.95)';
- document.querySelector('.card').style.opacity = '0';
- setTimeout(() => { window.location.href = '/'; }, 300);
+ fetch('/api/auth/login', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ username: user, password: pass })
+ }).then(function(res) {
+ return res.json().then(function(data) { return { ok: res.ok, data: data }; });
+ }).then(function(result) {
+ if (result.ok && result.data.token) {
+ localStorage.setItem('ns_token', result.data.token);
+ if (document.getElementById('rememberMe').checked) {
+ localStorage.setItem('ns_remember', 'true');
+ }
+ card.classList.add('exit');
+ setTimeout(function() { window.location.href = '/'; }, 350);
} else {
attempts++;
if (attempts >= 5) {
lockUntil = Date.now() + 30000;
- showError('Too many failed attempts. Locked for 30 seconds.');
+ showAlert(loginError, 'Account locked for 30 seconds', loginErrorText);
} else {
- showError(data.error || 'Invalid credentials');
+ showAlert(loginError, result.data.error || 'Invalid credentials', loginErrorText);
}
}
- } catch (err) {
- showError('Connection failed — is the server running?');
- } finally {
- btn.classList.remove('loading');
- btn.disabled = false;
- }
+ }).catch(function() {
+ showAlert(loginError, 'Connection failed — is the server running?', loginErrorText);
+ }).finally(function() {
+ btnLogin.classList.remove('loading');
+ btnLogin.disabled = false;
+ });
});
- function showError(msg) {
- errorText.textContent = msg;
- errorBox.classList.add('show');
- // Shake animation
- errorBox.style.animation = 'none';
- errorBox.offsetHeight; // reflow
- errorBox.style.animation = 'shake .4s ease';
- }
+ /* ── register ── */
+ regForm.addEventListener('submit', function(e) {
+ e.preventDefault();
+ hideAlerts();
- // Keyboard shortcut: Enter submits from either field
- document.addEventListener('keydown', function(e) {
- if (e.key === 'Enter' && document.activeElement.tagName !== 'BUTTON') {
- form.dispatchEvent(new Event('submit'));
+ var user = document.getElementById('regUser').value.trim();
+ var pass = regPassConfirm.value;
+ if (!user) { showAlert(regError, 'Please enter a username', regErrorText); return; }
+ if (user.length < 3) { showAlert(regError, 'Username must be at least 3 characters', regErrorText); return; }
+ if (!pass) { showAlert(regError, 'Please confirm the password', regErrorText); return; }
+ if (pass !== currentGenPw) {
+ showAlert(regError, 'Password does not match the generated one. Copy and paste it.', regErrorText);
+ return;
}
+
+ btnRegister.classList.add('loading');
+ btnRegister.disabled = true;
+
+ fetch('/api/auth/register', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ username: user, password: pass })
+ }).then(function(res) {
+ return res.json().then(function(data) { return { ok: res.ok, data: data }; });
+ }).then(function(result) {
+ if (result.ok) {
+ regSuccess.classList.add('show');
+ setTimeout(function() {
+ panelRegister.classList.remove('active');
+ panelLogin.classList.add('active');
+ hideAlerts();
+ document.getElementById('loginUser').value = user;
+ document.getElementById('loginPass').focus();
+ }, 1500);
+ } else {
+ showAlert(regError, result.data.error || 'Registration failed', regErrorText);
+ }
+ }).catch(function() {
+ showAlert(regError, 'Connection failed', regErrorText);
+ }).finally(function() {
+ btnRegister.classList.remove('loading');
+ btnRegister.disabled = false;
+ });
});
})();
-
-