From e28dfbe60330e11133a558ffb00a41f2f4ac96c4 Mon Sep 17 00:00:00 2001 From: lauralani Date: Fri, 18 Aug 2023 21:11:30 +0200 Subject: [PATCH] add hashing logic and post stuff --- index.html | 4 ++-- static/script.js | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 5427cbd..092ec27 100644 --- a/index.html +++ b/index.html @@ -10,10 +10,10 @@ - Starter template - Halfmoon + matrix.lila.network - Registration - + diff --git a/static/script.js b/static/script.js index 7d6fe9b..73d74c0 100644 --- a/static/script.js +++ b/static/script.js @@ -1,4 +1,4 @@ -async function handleSubmit() { +async function submitForm() { var nonce_request = await fetch("https://matrix-reg.test.lauka.dev/_synapse/admin/v1/register", { method: 'GET', redirect: 'follow', @@ -7,6 +7,7 @@ async function handleSubmit() { var nonce = await nonce_request.json() var username = document.getElementById("username").value + var displayname = document.getElementById("displayname").value var password = document.getElementById("password").value var sharedsecret = document.getElementById("sharedsecret").value var admin = "notadmin" @@ -14,7 +15,25 @@ async function handleSubmit() { var string = `${nonce.nonce}\0${username}\0${password}\0${admin}` - const hash = new jsSHA("SHA-1", "TEXT", { hmacKey : { value : sharedsecret, format: "TEXT" }}) + const hasher = new jsSHA("SHA-1", "TEXT", { hmacKey : { value : sharedsecret, format: "TEXT" }}) + hasher.update(string) + var hmac = hasher.getHash('HEX') + + var register_body = JSON.stringify({ + "nonce": nonce.nonce, + "username": displayname, + "password": password, + "admin": false, + "mac": hmac + }) + + var register_request = await fetch("https://matrix-reg.test.lauka.dev/_synapse/admin/v1/register", { + method: 'POST', + mode: "cors", + body: register_body + }) + + } function HandlePasswordInput() {