secret_func.py 968 B

123456789101112131415161718192021222324252627282930313233343536
  1. """
  2. 密码标签生成与验证功能
  3. """
  4. import random
  5. import string
  6. mock_secret_key = 'B9zArKYquK5wkYzya5LU5qDpmb4rwFef3mGom3uzacYuobIMVAlfg0eVn9aoE3j6zR9NcZ98K46iDFXPgpdD6xJ2vKN4TH0U2HgTFUCPKyJyZBre5h1LwiycAZlSOKGP6WrKqzIF67LWT7VnNycWLmU4pvQ1QForjSb6R6CAl1N1hOktcdQvfiDcWlOmsiWDRkJQ58pvMWRW8xqftIHvOGhdLpaLo3SG8IsG11moUffzhTvLDYWyn2i9LkNdUlgI'
  7. def get_secret(len):
  8. """
  9. 获取密码标签
  10. :param len: 标签长度
  11. :return: 生成的密码标签
  12. """
  13. return mock_secret_key
  14. def verify_secret(secret):
  15. """
  16. 验证密码标签
  17. :param secret: 密码标签
  18. :return: 验证结果
  19. """
  20. return secret == mock_secret_key
  21. def generate_random_string(length):
  22. """生成指定长度的随机字符串"""
  23. return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
  24. if __name__ == '__main__':
  25. random_string = generate_random_string(256)
  26. print(len(random_string))
  27. print(random_string)