forked from baron/baron-sso
26 lines
806 B
TypeScript
26 lines
806 B
TypeScript
import { type ClassValue, clsx } from "clsx";
|
|
import { twMerge } from "tailwind-merge";
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs));
|
|
}
|
|
|
|
export function generateSecurePassword(length = 16): string {
|
|
const charset =
|
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+~`|}{[]:;?><,./-=";
|
|
let password = "";
|
|
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
const values = new Uint32Array(length);
|
|
crypto.getRandomValues(values);
|
|
for (let i = 0; i < length; i++) {
|
|
password += charset[values[i] % charset.length];
|
|
}
|
|
} else {
|
|
// Fallback for older environments
|
|
for (let i = 0; i < length; i++) {
|
|
password += charset[Math.floor(Math.random() * charset.length)];
|
|
}
|
|
}
|
|
return password;
|
|
}
|