Guest User

Untitled

a guest
Jan 25th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. """ User validation class"""
  2.  
  3. from abc import ABC, abstractmethod
  4. import re
  5.  
  6.  
  7. class UserValidation(ABC):
  8. def __init__(self, username, email, password):
  9. self.username = username
  10. self.email = email
  11. self.password = password
  12.  
  13. @abstractmethod
  14. def check_username(self):
  15. regex = '^[a-zA-Z0-9]([._](?![._])|[a-zA-Z0-9]){6,18}[a-zA-Z0-9]$'
  16. if re.match(regex, self.username):
  17. return True
  18.  
  19. raise ValueError('wrong username syntax')
  20.  
  21. @abstractmethod
  22. def check_password(self):
  23. while True:
  24. if 8 > len(self.password):
  25. check = -1
  26. break
  27. elif not re.search("[a-z]", self.password):
  28. check = -1
  29. break
  30. elif not re.search("[A-Z]", self.password):
  31. check = -1
  32. break
  33. elif not re.search("[0-9]", self.password):
  34. check = -1
  35. break
  36. elif not re.search("[_@$!}[{(0*#%^&]", self.password):
  37. check = -1
  38. break
  39. elif re.search("\s", self.password):
  40. check = -1
  41. break
  42. else:
  43. check = 0
  44. return True
  45.  
  46. if check == -1:
  47. raise ValueError('Password is not secure')
  48.  
  49. @abstractmethod
  50. def check_email(self):
  51. match = re.search("(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9]+\.[a-zA-Z0-9.]*\.*[com|org|edu]{3}$)", self.email)
  52. if match:
  53. return True
  54. raise ValueError('Email syntax is wrong')
Add Comment
Please, Sign In to add comment