Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User(Document):
- email = StringField(required=True)
- username = StringField(required=True)
- password = StringField(required=True)
- salt = StringField(required=True)
- @classmethod
- def create(cls, email, username, password):
- '''Call this method instead of directly instiating yourself.
- This will correctly salt the password in the database.
- Returns a User object
- '''
- salt = gen_random_string(random.randint(5, 30))
- salted = sha512(salt + password).hexdigest()
- user = User(email=email, username=username, password=salted,
- salt=salt)
- return user
- def __eq__(self, other):
- return sha512(self.salt + other) == self.password
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement