def set_password(self, password): to_store = '' if password: salt = utils.gen_salt() hash = utils.gen_hash(password=password, salt=salt) algorithm = 'sha1' to_store = '|'.join((algorithm, hash, salt)) self.password = to_store return to_store
def authenticate(self, email, password): success = False if email and password: try: (algorithm, stored_hash, salt) = self.password.split('|') new_hash = utils.gen_hash(password=password, salt=salt) if stored_hash == new_hash: success = True except Exception: pass return success