parent
6c6cbdc1a5
commit
d5cc6d5067
|
@ -1,11 +1,7 @@
|
|||
// Returns a cryptographically random hexadecimal string of length `length`
|
||||
// (thus containing 4*`length` bits of entropy).
|
||||
export const randomString = (length = 12) => {
|
||||
const bytes = new Uint8Array(Math.ceil(length / 2))
|
||||
crypto.getRandomValues(bytes)
|
||||
const hex = bytes.reduce((s, b) => s + ('0' + b.toString(16)).slice(-2), '')
|
||||
return hex.substring(0, length)
|
||||
}
|
||||
export const randomString = (length = 12) =>
|
||||
Math.random()
|
||||
.toString(16)
|
||||
.substring(2, length + 2)
|
||||
|
||||
export function genHash(str: string) {
|
||||
// xmur3
|
||||
|
|
|
@ -42,7 +42,8 @@ export const createUser = functions
|
|||
const name = cleanDisplayName(rawName)
|
||||
let username = cleanUsername(name)
|
||||
|
||||
while (await getUserByUsername(username)) {
|
||||
const sameNameUser = await getUserByUsername(username)
|
||||
if (sameNameUser) {
|
||||
username += randomString(4)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user