Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User(db.Model):
- email = db.EmailProperty()
- salt = db.StringProperty()
- password = db.StringProperty()
- first_name = db.StringProperty()
- last_name = db.StringProperty()
- organization = db.ReferenceProperty(Organization)
- stati = db.StringListProperty()
- ORDERING = ('last_name', 'first_name')
- USEFUL_FIELDS = (
- 'email',
- 'salt',
- 'password',
- 'first_name',
- 'last_name',
- 'stati')
- @staticmethod
- def generate_password(plaintext_pwd = None):
- if plaintext_pwd is None:
- pwd = []
- for i in range(16):
- pwd.append(random.choice(salt_chars))
- plaintext_pwd = ''.join(pwd)
- del pwd
- salt = []
- for i in xrange(64):
- salt.append(random.choice(salt_chars))
- salt = ''.join(salt)
- return (salt, hashlib.sha512(salt + plaintext_pwd).hexdigest(), plaintext_pwd)
- @staticmethod
- def get_user(email, password):
- user = User.all().filter('email =', email).filter('stati =', 'active').get()
- if user is None:
- return None
- salt = user.salt
- candidate_hash = hashlib.sha512(salt + password).hexdigest()
- if user.password == candidate_hash:
- return user
- else:
- return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement