Browse Source

fix:修复文件密码校验bug

master
刘子旺 7 months ago
parent
commit
cb0d21abeb
  1. 6
      godo/files/os.go
  2. 30
      godo/files/pwdfile.go

6
godo/files/os.go

@ -378,11 +378,7 @@ func GetPwdFlag() (bool, error) {
isPwd, has := libs.GetConfig("isPwd") isPwd, has := libs.GetConfig("isPwd")
if !has { if !has {
// 默认不加密 // 默认不加密
req := libs.ReqBody{ err := libs.SetConfigByName("isPwd", false)
Name: "isPwd",
Value: false,
}
err := libs.SetConfig(req)
if err != nil { if err != nil {
return false, err return false, err
} }

30
godo/files/pwdfile.go

@ -18,7 +18,6 @@ func HandleReadFile(w http.ResponseWriter, r *http.Request) {
libs.HTTPError(w, http.StatusInternalServerError, err.Error()) libs.HTTPError(w, http.StatusInternalServerError, err.Error())
return return
} }
// 检查是否需要密码,如果需要,则从请求头中获取文件密码和盐值 // 检查是否需要密码,如果需要,则从请求头中获取文件密码和盐值
var fPwd string var fPwd string
var salt string var salt string
@ -89,34 +88,27 @@ func HandleReadFile(w http.ResponseWriter, r *http.Request) {
// 设置文件密码 // 设置文件密码
func HandleSetFilePwd(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) // 获取盐值 salt, err := GetSalt(r) // 获取盐值
// 处理获取盐值时的错误 // 处理获取盐值时的错误
if err != nil { if err != nil || fPwd == "" {
libs.HTTPError(w, http.StatusInternalServerError, err.Error()) libs.HTTPError(w, http.StatusInternalServerError, err.Error())
return return
} }
// 服务端再hash加密 // 服务端再hash加密
// "Lqda0ez6DeBhKOHDUklSO1SDJ7QAwHLgUqFYFfN6kU4="
hashPwd := libs.HashPassword(fPwd, salt) hashPwd := libs.HashPassword(fPwd, salt)
// 服务端存储 // 服务端存储
reqPwd := libs.ReqBody{ err = libs.SetConfigByName("filePwd", hashPwd)
Name: "filePwd",
Value: hashPwd,
}
err = libs.SetConfig(reqPwd)
if err != nil { if err != nil {
libs.HTTPError(w, http.StatusInternalServerError, err.Error()) libs.HTTPError(w, http.StatusInternalServerError, err.Error())
return return
} }
// salt值存储 // salt值存储
reqSalt := libs.ReqBody{ err = libs.SetConfigByName("salt", salt)
Name: "salt",
Value: salt,
}
err = libs.SetConfig(reqSalt)
if err != nil { if err != nil {
libs.HTTPError(w, http.StatusInternalServerError, err.Error()) libs.HTTPError(w, http.StatusInternalServerError, err.Error())
return return
@ -134,11 +126,7 @@ func HandleChangeFilePwd(w http.ResponseWriter, r *http.Request) {
return return
} }
newPwd := libs.HashPassword(filePwd, salt) newPwd := libs.HashPassword(filePwd, salt)
pwdReq := libs.ReqBody{ err = libs.SetConfigByName("filePwd", newPwd)
Name: "filePwd",
Value: newPwd,
}
err = libs.SetConfig(pwdReq)
if err != nil { if err != nil {
libs.HTTPError(w, http.StatusInternalServerError, err.Error()) libs.HTTPError(w, http.StatusInternalServerError, err.Error())
return return
@ -161,11 +149,7 @@ func HandleSetIsPwd(w http.ResponseWriter, r *http.Request) {
} else { } else {
isPwdBool = true isPwdBool = true
} }
pwdReq := libs.ReqBody{ err = libs.SetConfigByName("isPwd", isPwdBool)
Name: "isPwd",
Value: isPwdBool,
}
err = libs.SetConfig(pwdReq)
if err != nil { if err != nil {
libs.HTTPError(w, http.StatusInternalServerError, err.Error()) libs.HTTPError(w, http.StatusInternalServerError, err.Error())
return return

Loading…
Cancel
Save