Skip to content

Commit

Permalink
为了安全,更改为全部在Public库读取,password在源码里(重构v2.0.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
ANDYzytnb authored Sep 7, 2024
1 parent acafd6f commit 9e9250b
Showing 1 changed file with 8 additions and 25 deletions.
33 changes: 8 additions & 25 deletions GuessTheNumber.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
import requests
import base64
import random
import os
import subprocess

# GitHub API 配置
github_token = "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" # 替换为你的 GitHub 访问令牌
password_file_url = "https://api.github.com/repos/ANDYzytnb/GuessTheNumberDeveloperPasswordAPI/contents/password.txt"
private_repo_api_url = "https://api.github.com/repos/ANDYzytnb/GuessTheNumber/releases/latest"
public_repo_api_url = "https://api.github.com/repos/ANDYzytnb/GuessTheNumberPublicDownloadAPI/releases/latest"
public_repo_base_url = "https://github.com/ANDYzytnb/GuessTheNumberPublicDownloadAPI/releases/download"
current_version = "v1.0.4"
current_version = "v2.0.0"

def get_password_from_github():
print("正在请求开发者密码...")
headers = {'Authorization': f'token {github_token}'}
try:
response = requests.get(password_file_url, headers=headers)
response.raise_for_status()
file_content = response.json()
password_encoded = file_content['content']
password_decoded = base64.b64decode(password_encoded).decode('utf-8').strip()
return password_decoded
except requests.exceptions.RequestException as e:
print(f"获取开发者密码时发生错误: {e}")
return None
# 开发者模式密码
dev_mode_password = "devmodepwd"

def get_latest_version():
print("正在检查更新...")
headers = {'Authorization': f'token {github_token}'}
try:
response = requests.get(private_repo_api_url, headers=headers)
response = requests.get(public_repo_api_url)
response.raise_for_status()
latest_release = response.json()
return latest_release['tag_name']
Expand Down Expand Up @@ -129,14 +113,13 @@ def select_difficulty():
elif choice == 4:
return *custom_range(), False, None
elif choice == 9:
password = input("请输入开发者密码:") # 先让用户输入密码,再请求
correct_password = get_password_from_github() # 请求 GitHub 密码
if correct_password and password == correct_password:
password = input("请输入开发者密码:") # 先让用户输入密码
if password == dev_mode_password:
print("密码正确,进入开发者模式。")
min_range, max_range = custom_range() # 让用户自定义范围
number_to_guess = random.randint(min_range, max_range)
print(f"当前版本:{current_version}")
print(f"OTA 请求 URL:{private_repo_api_url}")
print(f"OTA 请求 URL:{public_repo_api_url}")
print(f"开发者模式提示:正确的数字是 {number_to_guess}")
return min_range, max_range, True, number_to_guess
else:
Expand Down

0 comments on commit 9e9250b

Please sign in to comment.