- Rename packages/utils/ to packages/server-utils/ - Update all imports and package.json references - Add READMEs for frontend-utils, server-utils, and common packages - Update main README with new package structure Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
56 lines
1.2 KiB
TypeScript
56 lines
1.2 KiB
TypeScript
import {
|
|
hashPassword as hashPasswordUtil,
|
|
verifyPassword as verifyPasswordUtil,
|
|
} from "@reviq/server-utils";
|
|
import zxcvbn from "zxcvbn";
|
|
|
|
export interface PasswordValidationResult {
|
|
valid: boolean;
|
|
feedback: string[];
|
|
score: number;
|
|
}
|
|
|
|
/**
|
|
* Validate password strength using zxcvbn
|
|
* @param password - The password to validate
|
|
* @param userInputs - User-specific inputs to penalize (email, display name)
|
|
* @returns Validation result with feedback if invalid
|
|
*/
|
|
export const validatePassword = (
|
|
password: string,
|
|
userInputs: string[] = [],
|
|
): PasswordValidationResult => {
|
|
const result = zxcvbn(password, userInputs);
|
|
|
|
if (result.score < 3) {
|
|
const feedback =
|
|
result.feedback.suggestions.length > 0
|
|
? result.feedback.suggestions
|
|
: [
|
|
"Password is too weak. Try a longer phrase or add numbers and symbols.",
|
|
];
|
|
|
|
return {
|
|
valid: false,
|
|
feedback,
|
|
score: result.score,
|
|
};
|
|
}
|
|
|
|
return {
|
|
valid: true,
|
|
feedback: [],
|
|
score: result.score,
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Hash a password using PBKDF2-SHA256 (Cloudflare Workers compatible)
|
|
*/
|
|
export const hashPassword = hashPasswordUtil;
|
|
|
|
/**
|
|
* Verify a password against a stored hash
|
|
*/
|
|
export const verifyPassword = verifyPasswordUtil;
|