Advertisement
Guest User

Untitled

a guest
May 31st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. class User(Document):
  2.     email = StringField(required=True)
  3.     username = StringField(required=True)
  4.     password = StringField(required=True)
  5.     salt = StringField(required=True)
  6.  
  7.     @classmethod
  8.     def create(cls, email, username, password):
  9.         '''Call this method instead of directly instiating yourself.
  10.           This will correctly salt the password in the database.
  11.           Returns a User object
  12.        '''
  13.         salt = gen_random_string(random.randint(5, 30))
  14.         salted = sha512(salt + password).hexdigest()
  15.         user = User(email=email, username=username, password=salted,
  16.                     salt=salt)
  17.         return user
  18.  
  19.     def __eq__(self, other):
  20.         return sha512(self.salt + other) == self.password
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement