Initial commit: ToNav Personal Navigation Page

- Flask + SQLite 个人导航页系统
- 前台导航页(分类Tab、卡片展示)
- 管理后台(服务管理、分类管理、健康检测)
- 响应式设计
- Systemd 服务配置
This commit is contained in:
OpenClaw Agent
2026-02-12 21:57:15 +08:00
commit 872526505e
22 changed files with 3424 additions and 0 deletions

38
utils/auth.py Normal file
View File

@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
"""认证工具"""
import hashlib
import sqlite3
from config import Config
def hash_password(password):
"""密码哈希SHA256简单版"""
return hashlib.sha256(password.encode()).hexdigest()
def verify_password(password, stored_hash):
"""验证密码"""
return hash_password(password) == stored_hash
def authenticate(username, password):
"""用户认证"""
conn = sqlite3.connect(Config.DATABASE_PATH)
cursor = conn.cursor()
cursor.execute('''
SELECT id, username, password_hash FROM users
WHERE username = ?
''', (username,))
user = cursor.fetchone()
conn.close()
if user and verify_password(password, user[2]):
return {
'id': user[0],
'username': user[1]
}
return None
def is_logged_in(session):
"""检查是否已登录"""
return 'user_id' in session