我正在 Django 中构建一个测试应用程序,它使用模块 Django RestFramework API Key 生成 api 密钥。(参考这里:https ://florimondmanca.github.io/djangorestframework-api-key/ )
我想在生成的密钥中间包含一些符号或连字符。
我已经尝试过模块中的默认密钥生成器,但我想让它更安全。
#models.py
from rest_framework_api_key.models import BaseAPIKeyManager
from rest_framework_api_key.crypto import KeyGenerator
from rest_framework_api_key.models import AbstractAPIKey
class UserCompanyAPIKeyManager(BaseAPIKeyManager):
key_generator = KeyGenerator(prefix_length=32, secret_key_length=32)
class UserCompanyAPIKey(AbstractAPIKey):
objects = UserCompanyAPIKeyManager()
输出:
前缀 = jlxGg6bnRdjtrW3Xr6Q6yUMKWAuc0D2u