Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ User validation class"""
- from abc import ABC, abstractmethod
- import re
- class UserValidation(ABC):
- def __init__(self, username, email, password):
- self.username = username
- self.email = email
- self.password = password
- @abstractmethod
- def check_username(self):
- regex = '^[a-zA-Z0-9]([._](?![._])|[a-zA-Z0-9]){6,18}[a-zA-Z0-9]$'
- if re.match(regex, self.username):
- return True
- raise ValueError('wrong username syntax')
- @abstractmethod
- def check_password(self):
- while True:
- if 8 > len(self.password):
- check = -1
- break
- elif not re.search("[a-z]", self.password):
- check = -1
- break
- elif not re.search("[A-Z]", self.password):
- check = -1
- break
- elif not re.search("[0-9]", self.password):
- check = -1
- break
- elif not re.search("[_@$!}[{(0*#%^&]", self.password):
- check = -1
- break
- elif re.search("\s", self.password):
- check = -1
- break
- else:
- check = 0
- return True
- if check == -1:
- raise ValueError('Password is not secure')
- @abstractmethod
- def check_email(self):
- match = re.search("(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9]+\.[a-zA-Z0-9.]*\.*[com|org|edu]{3}$)", self.email)
- if match:
- return True
- raise ValueError('Email syntax is wrong')
Add Comment
Please, Sign In to add comment