增加生成密码功能
This commit is contained in:
parent
47f66bee9b
commit
daddf70090
21
bin/update_password.sh
Normal file
21
bin/update_password.sh
Normal file
@ -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
|
||||
@ -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"
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user