Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. class User(db.Model):
  2.   email = db.EmailProperty()
  3.   salt = db.StringProperty()
  4.   password = db.StringProperty()
  5.   first_name = db.StringProperty()
  6.   last_name = db.StringProperty()
  7.   organization = db.ReferenceProperty(Organization)
  8.   stati = db.StringListProperty()
  9.   ORDERING = ('last_name', 'first_name')
  10.   USEFUL_FIELDS = (
  11.       'email',
  12.       'salt',
  13.       'password',
  14.       'first_name',
  15.       'last_name',
  16.       'stati')
  17.  
  18.   @staticmethod
  19.   def generate_password(plaintext_pwd = None):
  20.     if plaintext_pwd is None:
  21.       pwd = []
  22.       for i in range(16):
  23.         pwd.append(random.choice(salt_chars))
  24.       plaintext_pwd = ''.join(pwd)
  25.       del pwd
  26.     salt = []
  27.     for i in xrange(64):
  28.       salt.append(random.choice(salt_chars))
  29.     salt = ''.join(salt)
  30.     return (salt, hashlib.sha512(salt + plaintext_pwd).hexdigest(), plaintext_pwd)
  31.  
  32.   @staticmethod
  33.   def get_user(email, password):
  34.     user = User.all().filter('email =', email).filter('stati =', 'active').get()
  35.     if user is None:
  36.       return None
  37.     salt = user.salt
  38.     candidate_hash = hashlib.sha512(salt + password).hexdigest()
  39.     if user.password == candidate_hash:
  40.       return user
  41.     else:
  42.       return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement