diff --git a/godo/files/os.go b/godo/files/os.go index d35b024..6bc0f78 100644 --- a/godo/files/os.go +++ b/godo/files/os.go @@ -28,6 +28,7 @@ import ( "godo/libs" "io" "io/fs" + "log/slog" "net/http" "os" "path/filepath" @@ -342,12 +343,13 @@ func CheckFilePwd(fpwd, salt string) bool { // 1. 对输入的密码进行哈希 pwd := libs.HashPassword(fpwd, salt) // 2. 获取存储的密码哈希 - oldpwd, err := libs.GetConfig("filePwd") - if !err { + oldPwd, isHas := libs.GetConfig("filePwd") + if !isHas { + slog.Error("文件密码获取失败") return false } // 3. 比对密码哈希 - return oldpwd == pwd + return oldPwd == pwd } func IsHavePwd(pwd string) bool { @@ -380,8 +382,10 @@ func GetPwdFlag() (bool, error) { Name: "isPwd", Value: false, } - libs.SetConfig(req) - libs.SaveConfig() + err := libs.SetConfig(req) + if err != nil { + return false, err + } return false, nil // 返回默认值和无错误 } diff --git a/godo/files/pwdfile.go b/godo/files/pwdfile.go index 6a8e095..bcb45d1 100644 --- a/godo/files/pwdfile.go +++ b/godo/files/pwdfile.go @@ -101,18 +101,26 @@ func HandleSetFilePwd(w http.ResponseWriter, r *http.Request) { hashPwd := libs.HashPassword(fPwd, salt) // 服务端存储 - req := libs.ReqBody{ + reqPwd := libs.ReqBody{ Name: "filePwd", Value: hashPwd, } - libs.SetConfig(req) + err = libs.SetConfig(reqPwd) + if err != nil { + libs.HTTPError(w, http.StatusInternalServerError, err.Error()) + return + } // salt值存储 reqSalt := libs.ReqBody{ Name: "salt", Value: salt, } - libs.SetConfig(reqSalt) + err = libs.SetConfig(reqSalt) + if err != nil { + libs.HTTPError(w, http.StatusInternalServerError, err.Error()) + return + } res := libs.APIResponse{Message: "密码设置成功"} json.NewEncoder(w).Encode(res) } @@ -130,7 +138,11 @@ func HandleChangeFilePwd(w http.ResponseWriter, r *http.Request) { Name: "filePwd", Value: newPwd, } - libs.SetConfig(pwdReq) + err = libs.SetConfig(pwdReq) + if err != nil { + libs.HTTPError(w, http.StatusInternalServerError, err.Error()) + return + } libs.SuccessMsg(w, "success", "The file password change success!") } @@ -153,7 +165,10 @@ func HandleSetIsPwd(w http.ResponseWriter, r *http.Request) { Name: "isPwd", Value: isPwdBool, } - libs.SetConfig(pwdReq) - libs.SaveConfig() + err = libs.SetConfig(pwdReq) + if err != nil { + libs.HTTPError(w, http.StatusInternalServerError, err.Error()) + return + } libs.SuccessMsg(w, "success", "") }