diff --git a/server/controllers/down.go b/server/controllers/down.go index 3f2ac7fb..c6601497 100644 --- a/server/controllers/down.go +++ b/server/controllers/down.go @@ -3,6 +3,7 @@ package controllers import ( "github.com/Xhofe/alist/alidrive" "github.com/Xhofe/alist/server/models" + "github.com/Xhofe/alist/utils" "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" "path/filepath" @@ -31,7 +32,7 @@ func Down(c *gin.Context) { c.JSON(200, MetaResponse(500, err.Error())) return } - if fileModel.Password != "" && fileModel.Password != down.Password { + if fileModel.Password != "" && fileModel.Password != utils.Get16MD5Encode(down.Password) { if down.Password == "" { c.JSON(200, MetaResponse(401, "need password.")) } else { diff --git a/test/string_test.go b/test/string_test.go index e28a0842..bd5a533a 100644 --- a/test/string_test.go +++ b/test/string_test.go @@ -2,6 +2,7 @@ package test import ( "fmt" + "github.com/Xhofe/alist/utils" "path/filepath" "strings" "testing" @@ -24,4 +25,8 @@ func TestPassword(t *testing.T) { func TestDir(t *testing.T) { dir,file:=filepath.Split("root") fmt.Printf("dir:%s\nfile:%s\n",dir,file) +} + +func TestMD5(t *testing.T) { + fmt.Printf("%s\n", utils.Get16MD5Encode("123456")) } \ No newline at end of file diff --git a/utils/md5.go b/utils/md5.go new file mode 100644 index 00000000..32b5d37c --- /dev/null +++ b/utils/md5.go @@ -0,0 +1,18 @@ +package utils + +import ( + "crypto/md5" + "encoding/hex" +) + +//返回一个32位md5加密后的字符串 +func GetMD5Encode(data string) string { + h := md5.New() + h.Write([]byte(data)) + return hex.EncodeToString(h.Sum(nil)) +} + +//返回一个16位md5加密后的字符串 +func Get16MD5Encode(data string) string{ + return GetMD5Encode(data)[8:24] +}