Files
Meshray-Manager/docs/密码重置功能更新.md
T
2026-06-30 15:14:37 +08:00

169 lines
3.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# MeshRay 密码重置功能 - 最新更新
**更新时间**: 2026-03-25
**版本**: v2.0.0+
---
## 🎉 重要更新
### 之前:需要独立的 reset-password.exe
**旧方式**:
```bash
# 需要先编译独立工具
go build -o reset-password.exe cmd/reset-password/main.go
.\reset-password.exe
```
### 现在:直接集成在 meshray.exe 中
**新方式**:
```bash
# 直接使用主程序命令
.\meshray.exe reset-password
```
---
## 📋 使用方法
### 方法 1: 自动生成随机密码
```powershell
cd E:\Project\MeshRay
.\meshray.exe reset-password
```
**输出**:
```
MeshRay - 重置管理员密码
=========================
========================================
✅ 管理员密码已重置
========================================
用户名:admin
新密码:oZb18/up9If/aCuQ
****************************************
⚠️ 请妥善保管密码,建议登录后立即修改
========================================
```
---
### 方法 2: 手动指定新密码
```powershell
.\meshray.exe reset-password -p "MyNewPassword123"
```
**参数**:
- `-p`: 指定新密码
- `--password`: 同上(完整形式)
---
## 🔧 技术实现
### 代码位置
**文件**: [`cmd/meshray/main.go`](file://e:/Project/MeshRay/cmd/meshray/main.go)
**关键代码**:
```go
func main() {
// 检查命令行参数
if len(os.Args) > 1 && os.Args[1] == "reset-password" {
runResetPassword()
return
}
// ... 正常启动流程
}
// runResetPassword 重置管理员密码
func runResetPassword() {
// 1. 加载配置
cfg, _ := config.Load("")
// 2. 连接数据库
store, _ := store.New(cfg.Database.Path)
defer store.Close()
// 3. 创建用户服务
userService := service.NewUserService(store)
// 4. 生成或使用指定密码
var newPassword string
if len(os.Args) > 2 && (os.Args[2] == "-p" || os.Args[2] == "--password") {
newPassword = os.Args[3]
} else {
newPassword = service.GenerateRandomPassword(16)
}
// 5. 重置密码
userService.ResetAdminPassword(newPassword)
// 6. 输出结果
fmt.Println("✅ 管理员密码已重置")
fmt.Printf("新密码:%s\n", newPassword)
}
```
---
## ✅ 测试验证
### 测试 1: 自动生成密码
```powershell
PS E:\Project\MeshRay> .\meshray.exe reset-password
编译成功
新密码oZb18/up9If/aCuQ
```
### 测试 2: 指定密码
```powershell
PS E:\Project\MeshRay> .\meshray.exe reset-password -p "Test123!"
编译成功
新密码Test123!
```
---
## 🆚 对比
| 特性 | 旧方式 (独立工具) | 新方式 (集成命令) |
|------|------------------|------------------|
| **编译** | ❌ 需单独编译 | ✅ 无需额外编译 |
| **文件数** | ❌ 2 个 exe 文件 | ✅ 1 个 exe 文件 |
| **使用便利性** | ⭐⭐ | ⭐⭐⭐⭐⭐ |
| **维护成本** | 高 | 低 |
| **发现性** | 低(容易忘记) | 高(meshray 自带) |
---
## 📝 完整文档
详细文档请查看:[`README-重置密码.md`](file://e:/Project/MeshRay/README-重置密码.md)
---
## 💡 常见问题
### Q: 运行时才能用吗?
**A**: 是的!只要 `meshray.exe` 存在即可使用,无论是否在运行。
### Q: 会影响正在运行的服务吗?
**A**: 不会!密码立即生效,已登录的会话不受影响。
### Q: 还需要 reset-password.exe 吗?
**A**: ❌ 不需要了!已经集成到主程序中。
---
**更新完成!** 🎉