SHARE
TWEET

Untitled

a guest May 31st, 2017 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top