def add_user(self, name, password, active=True, roles=[], authentication_method=None): users = self.read() if users.get(name): return False if authentication_method is None: from app import get_default_authentication_method authentication_method = get_default_authentication_method() new_user = { 'active': active, 'roles': roles, 'authentication_method': authentication_method, 'authenticated': False } if authentication_method == 'hash': new_user['hash'] = make_salted_hash(password) elif authentication_method == 'cleartext': new_user['password'] = password else: raise NotImplementedError(authentication_method) users[name] = new_user self.write(users) userdata = users.get(name) return User(self, name, userdata)
def check_password(self, password): authentication_method = self.data.get('authentication_method', None) if authentication_method is None: from app import get_default_authentication_method authentication_method = get_default_authentication_method() if authentication_method == 'hash': result = check_hashed_password(password, self.get('hash')) elif authentication_method == 'cleartext': result = (self.get('password') == password) else: raise NotImplementedError(authentication_method) return result