Skip to content

Commit

Permalink
Add: Initialization user password document (#127)
Browse files Browse the repository at this point in the history
* 初始化用户密码

初始化用户密码

* Update q13.md

* Update config.mts

* Create q13.md English

---------

Co-authored-by: Kris <116849421+cantoblanco@users.noreply.github.com>
  • Loading branch information
yumusb and cantoblanco authored Dec 14, 2024
1 parent 8f2af55 commit f8f6593
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 2 deletions.
6 changes: 4 additions & 2 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ function getGuideSidebarZhCN() {
{ text: '设置每月重置流量统计', link: '/guide/q6.html' },
{ text: '自定义 Agent 监控项目', link: '/guide/q7.html' },
{ text: '启用 GPU 监控', link: '/guide/q9.html' },
{ text: '真实 IP 请求头', link: '/guide/q12.html' }
{ text: '真实 IP 请求头', link: '/guide/q12.html' },
{ text: '初始化用户密码', link: '/guide/q13.html' }
]
},
{
Expand Down Expand Up @@ -265,7 +266,8 @@ function getGuideSidebarEnUS() {
{ text: 'Set Monthly Traffic Statistics ResetReset', link: '/en_US/guide/q6.html' },
{ text: 'Custom Agent Monitoring Items', link: '/en_US/guide/q7.html' },
{ text: 'Enable GPU monitoring', link: '/en_US/guide/q9.html' },
{ text: 'Real IP Request Header', link: '/en_US/guide/q12.html' }
{ text: 'Real IP Request Header', link: '/en_US/guide/q12.html' },
{ text: 'Initialize User Password', link: '/en_US/guide/q13.html' }
]
},
{
Expand Down
78 changes: 78 additions & 0 deletions docs/en_US/guide/q13.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
outline: deep
---

# Initialize User Password

If you forget the user password stored in the local database, it cannot be retrieved as it is encrypted using `bcrypt`. However, you can reset it by creating a default user account and then updating the password to your preference.

---

## Steps to Reset the Password

### 1. Stop the Dashboard Service

To ensure data consistency and prevent conflicts, it is recommended to stop the Dashboard before modifying the database.

---

### 2. Locate the Database File

The database file is typically located at:
```plaintext
/opt/nezha/dashboard/data/sqlite.db
```

---

### 3. Query and Reset the User Table

Use the SQLite command-line tool to interact with the database:

1. **Query Existing Users**:
Run the following command to list all existing users:
```bash
sqlite3 /opt/nezha/dashboard/data/sqlite.db "SELECT * FROM users;"
```

2. **Clear the User Table**:
If you need to reset the user table, run the following command to delete all user records:
```bash
sqlite3 /opt/nezha/dashboard/data/sqlite.db "DELETE FROM users;"
```

---

### 4. Restart the Dashboard

After modifying the database, restart the Dashboard to apply changes.

---

### 5. Login Using the Default Account

During initialization, the Dashboard checks if the user table is empty. If it is, a default user account is created automatically.
You can log in with the following credentials:
- **Username**: `admin`
- **Password**: `admin`

---

## Post-Reset Actions

Once logged in, it is strongly recommended to change the default password immediately for security reasons:
1. Go to **Profile → Personal Info**.
2. Select **Update Profile**.
3. Set a new, secure password.

---

## Important Notes

- **Backup Before Modifying**: Always create a backup of the database before making any changes:
```bash
cp /opt/nezha/dashboard/data/sqlite.db /opt/nezha/dashboard/data/sqlite.db.bak
```
- **Caution**: Clearing the user table will remove all existing user accounts, including administrators. Proceed only if you are certain about the operation.

---
98 changes: 98 additions & 0 deletions docs/guide/q13.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
outline: deep
---

# 初始化用户密码

由于本地数据库存储的用户密码是通过 `bcrypt` 加密后的,所以当遗忘后没办法找回明文。不过你可以借助初始化功能来创建一个原始用户后再修改密码为你喜爱的。


1. 找到数据库的路径
例如 `/opt/nezha/dashboard/data/sqlite.db`
2. 查询、删除现有用户
```shell
sqlite3 sqlite.db "select * from users"
sqlite3 sqlite.db "delete from users"
```
3. 重启面板服务
面板初始化过程中会判断,如果用户表为空,则尝试插入默认用户。
4. 尝试登录
不出意外,用户表里面已经插入了默认用户,用户名和密码 `admin`

---
outline: deep
---

# 初始化用户密码

当遗忘本地数据库中存储的用户密码时,无法直接找回明文密码,因为它已通过 `bcrypt` 加密。不过,可以通过重置功能创建一个原始用户,之后再修改密码为所需的密码。

---

## 操作步骤

### 1. 停止 Dashboard 服务

为了确保数据一致性和避免意外冲突,建议在修改数据库前先停止 Dashboard。

---

### 2. 找到数据库路径

通常,数据库文件存放在以下位置:
```plaintext
/opt/nezha/dashboard/data/sqlite.db
```

---

### 3. 查询和清空用户表

使用 SQLite 命令行工具操作数据库:

1. **查看现有用户**
运行以下命令查看用户表内容:
```bash
sqlite3 /opt/nezha/dashboard/data/sqlite.db "SELECT * FROM users;"
```
这将列出当前所有用户的记录。

2. **清空用户表**
如果您确认需要重置用户表,可运行以下命令清空:
```bash
sqlite3 /opt/nezha/dashboard/data/sqlite.db "DELETE FROM users;"
```

---

### 4. 重启 Dashboard 服务

完成数据库操作后,重新启动 Dashboard.

---

### 5. 登录默认账户

Dashboard 在初始化时会自动检测用户表是否为空。如果为空,将自动插入默认用户。
您可以使用以下默认账户登录:
- **用户名**`admin`
- **密码**`admin`

---

## 后续操作

登录成功后,建议立即修改默认密码以提高安全性:
1. 点击 **头像 → 个人信息**
2. 选择 **更新个人资料**
3. 修改密码,建议设置一个复杂度较高的密码。

---

## 注意事项

- 修改数据库前,请确保已备份原始数据库文件:
```bash
cp /opt/nezha/dashboard/data/sqlite.db /opt/nezha/dashboard/data/sqlite.db.bak
```
- **谨慎操作**:清空用户表将移除所有用户数据,包括管理员用户。确认后再执行。

0 comments on commit f8f6593

Please sign in to comment.