parent
6c6cbdc1a5
commit
d5cc6d5067
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user