self.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:jamdb 作者: CenterForOpenScience 项目源码 文件源码
def _authenticate(self, data):
        namespace = manager.get_namespace(data['namespace'])
        collection = namespace.get_collection(data['collection'])

        if not UserPlugin.is_enabled(collection):
            raise exceptions.PluginNotEnabled(UserPlugin.NAME)

        if not (
            collection.schema
            and 'password' in collection.schema._schema.get('required', [])
            and collection.schema._schema['properties']['password'] == self.PASSWORD_SCHEMA
        ):
            raise exceptions.BadRequest(title='Bad password schema', detail='The schema for password must be {} and must be a required field'.format(self.PASSWORD_SCHEMA))

        # TODO validate retrieved document
        doc = collection.read(data['username'])
        password = doc.data['password'].encode()

        hashed = await asyncio.get_event_loop().run_in_executor(None, lambda: bcrypt.hashpw(data['password'].encode(), password))

        if hashed == password:
            return SelfAuthProvider.type, '{}:{}'.format(namespace.ref, collection.ref), data['username'], 8
        raise exceptions.Unauthorized()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号