From 5c6344cac0472f5ff39db788bc6c0baecc5f6bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=87=89?= <36558727+Xhofe@users.noreply.github.com> Date: Sun, 14 Mar 2021 19:13:09 +0800 Subject: [PATCH] =?UTF-8?q?:sparkler:=20=E7=9B=B4=E9=93=BEurl=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E5=93=88=E5=B8=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/down.go | 3 ++- test/string_test.go | 5 +++++ utils/md5.go | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 utils/md5.go 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] +}