From c9bce409d298bbcfa8d8095c107ca2d282919a29 Mon Sep 17 00:00:00 2001 From: Michael Albert Date: Tue, 4 Feb 2020 11:04:56 +0100 Subject: [PATCH] Prefill user_id and password on user creation Change-Id: I3f604f38c1842f155f3b39da20ba45992ba522be --- src/components/users.js | 43 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/components/users.js b/src/components/users.js index 068b59e..d3b6b9c 100644 --- a/src/components/users.js +++ b/src/components/users.js @@ -60,6 +60,47 @@ export const UserList = props => ( ); +function generateRandomUser() { + const homeserver = localStorage.getItem("home_server"); + const user_id = + "@" + + Array(8) + .fill("0123456789abcdefghijklmnopqrstuvwxyz") + .map( + x => + x[ + Math.floor( + (crypto.getRandomValues(new Uint32Array(1))[0] / + (0xffffffff + 1)) * + x.length + ) + ] + ) + .join("") + + ":" + + homeserver; + + const password = Array(20) + .fill( + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~!@-#$" + ) + .map( + x => + x[ + Math.floor( + (crypto.getRandomValues(new Uint32Array(1))[0] / (0xffffffff + 1)) * + x.length + ) + ] + ) + .join(""); + + return { + id: user_id, + password: password, + }; +} + // https://matrix.org/docs/spec/appendices#user-identifiers const validateUser = regex( /^@[a-z0-9._=\-/]+:.*/, @@ -67,7 +108,7 @@ const validateUser = regex( ); export const UserCreate = props => ( - +