File size: 1,652 Bytes
bf954c9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | /**
* Auth Engine Input and Tenant Constraints Validators
*/
export class AuthValidators {
/**
* Safe check for email standard format
*/
static validateEmail(email: string): boolean {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
/**
* Student PIN must be numeric and match strict length guidelines (e.g. 4 or 6 digits)
*/
static validateStudentPin(pin: string, expectedLength: number = 4): { isValid: boolean; error?: string } {
if (!pin) return { isValid: false, error: 'Student Access PIN is required.' };
const numOnly = /^\d+$/;
if (!numOnly.test(pin)) {
return { isValid: false, error: 'Access PIN must contain digits only.' };
}
if (pin.length !== expectedLength) {
return { isValid: false, error: `Access PIN must be exactly ${expectedLength} digits.` };
}
return { isValid: true };
}
/**
* Validates robust tenant credentials for school pilot codes
*/
static validateSchoolCode(schoolCode: string): boolean {
if (!schoolCode) return false;
const sanit = schoolCode.trim().toLowerCase();
// Ensure school codes are alphanumeric with hyphens (e.g., "school-ltd-01")
return /^[a-z0-9]+(-[a-z0-9]+)*$/.test(sanit);
}
/**
* Enterprise-grade length checks for teacher registrations
*/
static validatePasswordStrength(password: string): { isValid: boolean; error?: string } {
if (!password || password.length < 8) {
return {
isValid: false,
error: 'Security password must compile to at least 8 alphanumeric elements.'
};
}
return { isValid: true };
}
}
|