Add login and register dialogs, user dropdown menu with profile link and logout option, and integrate with session management hook. Prevent hydration mismatches by conditionally rendering auth elements after mount. Update package-lock.json with new @esbuild dependencies for build tooling.
44 lines
1016 B
TypeScript
44 lines
1016 B
TypeScript
/**
|
|
* Módulo de hash e verificação de senhas
|
|
* Usa bcrypt para hashing seguro
|
|
*/
|
|
|
|
import bcrypt from "bcrypt";
|
|
|
|
const SALT_ROUNDS = 12;
|
|
|
|
/**
|
|
* Gera hash de senha usando bcrypt
|
|
* @param password - Senha em texto plano
|
|
* @returns Hash da senha
|
|
*/
|
|
export async function hashPassword(password: string): Promise<string> {
|
|
try {
|
|
const hash = await bcrypt.hash(password, SALT_ROUNDS);
|
|
return hash;
|
|
} catch (error) {
|
|
console.error("❌ Erro ao gerar hash de senha:", error);
|
|
throw new Error("Falha ao processar senha");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Compara senha em texto plano com hash
|
|
* @param password - Senha em texto plano
|
|
* @param hash - Hash armazenado
|
|
* @returns true se a senha corresponde, false caso contrário
|
|
*/
|
|
export async function comparePassword(
|
|
password: string,
|
|
hash: string
|
|
): Promise<boolean> {
|
|
try {
|
|
const match = await bcrypt.compare(password, hash);
|
|
return match;
|
|
} catch (error) {
|
|
console.error("❌ Erro ao comparar senha:", error);
|
|
return false;
|
|
}
|
|
}
|
|
|