Files
MyFit-CoreBackEnd/services/web/project/validate/validate.py
T
CHIEFSOFT\ameye 108378a31e first commit
2025-05-03 22:16:10 -04:00

46 lines
1.4 KiB
Python

"""Validator Module"""
import re
#from bson.objectid import ObjectId
def validate(data, regex):
"""Custom Validator"""
return True if re.match(regex, data) else False
def validate_password(password: str):
"""Password Validator"""
# print(password)
#reg = r"\b^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!#%*?&]{8,20}$\b"
reg = r"\b^[A-Za-z0-9@#$%^&+=]{8,}\b"
return validate(password, reg)
def validate_username(username: str):
if not 6 <= len(username.split(' ')) <= 20:
return {
'name': 'Username must be between 6 and 15 words'
}
return True
def validate_signup_data(firstname,lastname,email):
return True
def validate_complete_signup_data(username,password,country):
return True
def validate_username_and_password(username, password):
"""Username and Password Validator"""
if not (username and password):
return {
'username': 'Username is required',
'password': 'Password is required'
}
if not validate_username(username):
return {
'username': 'Username is invalid'
}
if not validate_password(password):
return {
'password': 'Password is invalid, Should be at least 8 characters with \
upper and lower case letters, numbers and special characters'
}
return True