From daddf70090ff0d2db709628232ede6794da42f42 Mon Sep 17 00:00:00 2001 From: Olia Lisa Date: Mon, 29 Dec 2025 17:24:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=9F=E6=88=90=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/update_password.sh | 21 +++++++++++++++++++++ bin/utils/base.sh | 13 +++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 bin/update_password.sh diff --git a/bin/update_password.sh b/bin/update_password.sh new file mode 100644 index 0000000..a1a7dd4 --- /dev/null +++ b/bin/update_password.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# 更新密码的函数 +update_password() { + local script_dir="$(dirname "$(realpath "$0")")" + local config_file="$script_dir/../config.json" + + # 加载工具脚本 + source "$script_dir/utils/base.sh" + + # 生成一个长度为16的随机密码 + local new_password=$(gen_password 16) + + # 修改密码 + sed -i 's/你的密码/'"$new_password"'/g' "$config_dir/config.json" + + echo "设置密码成功" +} + +# 调用函数 +update_password \ No newline at end of file diff --git a/bin/utils/base.sh b/bin/utils/base.sh index e5a6e4c..68b3198 100644 --- a/bin/utils/base.sh +++ b/bin/utils/base.sh @@ -84,3 +84,16 @@ install_docker_compose(){ chmod +x /usr/local/bin/docker-compose } + + +# 生成密码 +gen_password() { + local pass_length=$1 # 密码长度作为第一个参数 + local chars='[:alnum:]' # 只允许出现字母和数字 + + local rand + rand=$(< /dev/urandom tr -dc "$chars" | head -c "$pass_length") + + echo "$rand" +} +