Konga密码重置
1、登录数据库psql
pg-konga-postgresql-0:/$ psql -U konga -d konga
Password for user konga:
psql (11.20)
Type "help" for help.
konga=> \d+ konga_users;
Table "public.konga_users"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
-----------------+--------------------------+-----------+----------+-----------------------------------------+----------+--------------+-------------
id | integer | | not null | nextval('konga_users_id_seq'::regclass) | plain | |
username | text | | | | extended | |
email | text | | | | extended | |
firstName | text | | | | extended | |
lastName | text | | | | extended | |
admin | boolean | | | | plain | |
node_id | text | | | | extended | |
active | boolean | | | | plain | |
activationToken | text | | | | extended | |
node | integer | | | | plain | |
createdAt | timestamp with time zone | | | | plain | |
updatedAt | timestamp with time zone | | | | plain | |
createdUserId | integer | | | | plain | |
updatedUserId | integer | | | | plain | |
Indexes:
"konga_users_pkey" PRIMARY KEY, btree (id)
"konga_users_email_key" UNIQUE CONSTRAINT, btree (email)
"konga_users_username_key" UNIQUE CONSTRAINT, btree (username)
发现konga_users没有password字段
发现原来是password存在另一个表中
konga=> \d konga_passports
Table "public.konga_passports"
Column | Type | Collation | Nullable | Default
------------+--------------------------+-----------+----------+---------------------------------------------
id | integer | | not null | nextval('konga_passports_id_seq'::regclass)
protocol | text | | |
password | text | | |
provider | text | | |
identifier | text | | |
tokens | json | | |
user | integer | | |
createdAt | timestamp with time zone | | |
updatedAt | timestamp with time zone | | |
Indexes:
"konga_passports_pkey" PRIMARY KEY, btree (id)
2、编写加密脚本
import bcrypt
import sys
# 从命令行获取新密码,或者直接在这里设置
if len(sys.argv) > 1:
new_password = sys.argv[1]
else:
new_password = "sdfewfafa" # 在这里输入你的新密码
# 确保密码是字节串
password_bytes = new_password.encode('utf-8')
# 生成哈希 (rounds=10 是 bcrypt 的一个常见参数)
# Konga 0.14.9 可能使用默认 rounds,10 是个安全的猜测
hashed_password = bcrypt.hashpw(password_bytes, bcrypt.gensalt(rounds=10))
# 打印出可用于 SQL 更新的哈希字符串
print(hashed_password.decode('utf-8'))
python bcrypt_pass.py
$2b$10$s8MGdm7K4jDw8V7GDMNCLujZP1PehXVN2GoiPQedAu2Waib.fw7Pq
3、修改数据表密码
UPDATE konga_passports
SET password = '$2b$10$s8MGdm7K4jDw8V7GDMNCLujZP1PehXVN2GoiPQedAu2Waib.fw7Pq'
WHERE "user" = 1 AND provider = 'local';
其中user的id值是在konga_users中要改的账号的id
konga控制台也可以更改,但是目前没有生效
NODE_ENV=development node /app/bin/konga.js prepare --uri postgres://konga:sfdfef@pg-konga-postgresql.host:5432/konga --admin-user admin --admin-pass asdfefs