Revert "Better random (#213)"

This reverts commit c9f3644988.
This commit is contained in:
James Grugett 2022-05-16 20:26:51 -04:00
parent 6c6cbdc1a5
commit d5cc6d5067
2 changed files with 6 additions and 9 deletions

View File

@ -1,11 +1,7 @@
// Returns a cryptographically random hexadecimal string of length `length` export const randomString = (length = 12) =>
// (thus containing 4*`length` bits of entropy). Math.random()
export const randomString = (length = 12) => { .toString(16)
const bytes = new Uint8Array(Math.ceil(length / 2)) .substring(2, length + 2)
crypto.getRandomValues(bytes)
const hex = bytes.reduce((s, b) => s + ('0' + b.toString(16)).slice(-2), '')
return hex.substring(0, length)
}
export function genHash(str: string) { export function genHash(str: string) {
// xmur3 // xmur3

View File

@ -42,7 +42,8 @@ export const createUser = functions
const name = cleanDisplayName(rawName) const name = cleanDisplayName(rawName)
let username = cleanUsername(name) let username = cleanUsername(name)
while (await getUserByUsername(username)) { const sameNameUser = await getUserByUsername(username)
if (sameNameUser) {
username += randomString(4) username += randomString(4)
} }