login update
This commit is contained in:
1 parent
e2b2a39837
commit
2433cfb0af
2 files changed
+8
-9
No files matched your search
+2
-1
@@ -90,7 +90,8 @@
|
|||||||
|
|
||||||
<div id="summary" class="hidden"></div>
|
<div id="summary" class="hidden"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/jssha@3.4.0/dist/sha256.min.js"></script>
|
||||||
|
<script src="script.js"></script>
|
||||||
<script src="script.js"></script>
|
<script src="script.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
+6
-8
@@ -12,19 +12,17 @@ async function loadUsers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 🔐 Password hashing
|
// 🔐 Password hashing
|
||||||
async function hashPassword(password) {
|
function hashPassword(password) {
|
||||||
const msgUint8 = new TextEncoder().encode(password)
|
const shaObj = new jsSHA("SHA-256", "TEXT")
|
||||||
const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8)
|
shaObj.update(password)
|
||||||
return Array.from(new Uint8Array(hashBuffer))
|
return shaObj.getHash("HEX")
|
||||||
.map(b => b.toString(16).padStart(2, '0'))
|
|
||||||
.join('')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 👤 Login
|
// 👤 Login
|
||||||
async function verifyLogin() {
|
async function verifyLogin() {
|
||||||
const uname = document.getElementById('username').value.trim()
|
const uname = document.getElementById('username').value.trim()
|
||||||
const pw = document.getElementById('password').value
|
const pw = document.getElementById('password').value
|
||||||
const hash = await hashPassword(pw)
|
const hash = hashPassword(pw)
|
||||||
const msg = document.getElementById('loginMessage')
|
const msg = document.getElementById('loginMessage')
|
||||||
|
|
||||||
const user = users.find(u => u.username === uname && u.hash === hash)
|
const user = users.find(u => u.username === uname && u.hash === hash)
|
||||||
@@ -101,7 +99,7 @@ async function addNewUser() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const hash = await hashPassword(password)
|
const hash = hashPassword(password)
|
||||||
await saveUserToServer(username, hash, role)
|
await saveUserToServer(username, hash, role)
|
||||||
msg.textContent = `✅ User "${username}" added to server.`
|
msg.textContent = `✅ User "${username}" added to server.`
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user