first commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""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
|
||||
Reference in New Issue
Block a user