From cb0d21abebce7dc992276289351f85ad77a16f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=AD=90=E6=97=BA?= <15039612+liu-ziwang123@user.noreply.gitee.com> Date: Thu, 31 Oct 2024 12:00:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E6=A0=A1=E9=AA=8Cbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- godo/files/os.go | 6 +----- godo/files/pwdfile.go | 30 +++++++----------------------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/godo/files/os.go b/godo/files/os.go index 6bc0f78..0809acf 100644 --- a/godo/files/os.go +++ b/godo/files/os.go @@ -378,11 +378,7 @@ func GetPwdFlag() (bool, error) { isPwd, has := libs.GetConfig("isPwd") if !has { // 默认不加密 - req := libs.ReqBody{ - Name: "isPwd", - Value: false, - } - err := libs.SetConfig(req) + err := libs.SetConfigByName("isPwd", false) if err != nil { return false, err } diff --git a/godo/files/pwdfile.go b/godo/files/pwdfile.go index bcb45d1..c6b9401 100644 --- a/godo/files/pwdfile.go +++ b/godo/files/pwdfile.go @@ -18,7 +18,6 @@ func HandleReadFile(w http.ResponseWriter, r *http.Request) { libs.HTTPError(w, http.StatusInternalServerError, err.Error()) return } - // 检查是否需要密码,如果需要,则从请求头中获取文件密码和盐值 var fPwd string var salt string @@ -89,34 +88,27 @@ func HandleReadFile(w http.ResponseWriter, r *http.Request) { // 设置文件密码 func HandleSetFilePwd(w http.ResponseWriter, r *http.Request) { - fPwd := r.Header.Get("filepPwd") + fPwd := r.Header.Get("filePwd") salt, err := GetSalt(r) // 获取盐值 // 处理获取盐值时的错误 - if err != nil { + if err != nil || fPwd == "" { libs.HTTPError(w, http.StatusInternalServerError, err.Error()) return } // 服务端再hash加密 + // "Lqda0ez6DeBhKOHDUklSO1SDJ7QAwHLgUqFYFfN6kU4=" hashPwd := libs.HashPassword(fPwd, salt) // 服务端存储 - reqPwd := libs.ReqBody{ - Name: "filePwd", - Value: hashPwd, - } - err = libs.SetConfig(reqPwd) + err = libs.SetConfigByName("filePwd", hashPwd) if err != nil { libs.HTTPError(w, http.StatusInternalServerError, err.Error()) return } // salt值存储 - reqSalt := libs.ReqBody{ - Name: "salt", - Value: salt, - } - err = libs.SetConfig(reqSalt) + err = libs.SetConfigByName("salt", salt) if err != nil { libs.HTTPError(w, http.StatusInternalServerError, err.Error()) return @@ -134,11 +126,7 @@ func HandleChangeFilePwd(w http.ResponseWriter, r *http.Request) { return } newPwd := libs.HashPassword(filePwd, salt) - pwdReq := libs.ReqBody{ - Name: "filePwd", - Value: newPwd, - } - err = libs.SetConfig(pwdReq) + err = libs.SetConfigByName("filePwd", newPwd) if err != nil { libs.HTTPError(w, http.StatusInternalServerError, err.Error()) return @@ -161,11 +149,7 @@ func HandleSetIsPwd(w http.ResponseWriter, r *http.Request) { } else { isPwdBool = true } - pwdReq := libs.ReqBody{ - Name: "isPwd", - Value: isPwdBool, - } - err = libs.SetConfig(pwdReq) + err = libs.SetConfigByName("isPwd", isPwdBool) if err != nil { libs.HTTPError(w, http.StatusInternalServerError, err.Error()) return