mirror of
https://github.com/Since-3/since3-portal.git
synced 2026-10-12 21:41:16 +00:00
new clients functionality
This commit is contained in:
parent
9dbacf4d45
commit
5edd697056
25 changed files with 1268 additions and 56 deletions
29
lib/generate-password.ts
Normal file
29
lib/generate-password.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { randomInt } from "crypto"
|
||||
|
||||
const LOWERCASE = "abcdefghijkmnpqrstuvwxyz"
|
||||
const UPPERCASE = "ABCDEFGHJKLMNPQRSTUVWXYZ"
|
||||
const DIGITS = "23456789"
|
||||
const SYMBOLS = "!@#$%&*"
|
||||
const ALL_CHARS = LOWERCASE + UPPERCASE + DIGITS + SYMBOLS
|
||||
|
||||
export function generatePassword(length = 14) {
|
||||
const required = [
|
||||
LOWERCASE[randomInt(LOWERCASE.length)],
|
||||
UPPERCASE[randomInt(UPPERCASE.length)],
|
||||
DIGITS[randomInt(DIGITS.length)],
|
||||
SYMBOLS[randomInt(SYMBOLS.length)],
|
||||
]
|
||||
|
||||
const rest = Array.from({ length: length - required.length }, () =>
|
||||
ALL_CHARS[randomInt(ALL_CHARS.length)]
|
||||
)
|
||||
|
||||
const password = [...required, ...rest]
|
||||
|
||||
for (let i = password.length - 1; i > 0; i--) {
|
||||
const j = randomInt(i + 1)
|
||||
;[password[i], password[j]] = [password[j], password[i]]
|
||||
}
|
||||
|
||||
return password.join("")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue