🎇 直链url密码哈希
This commit is contained in:
@ -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 {
|
||||
|
@ -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"))
|
||||
}
|
18
utils/md5.go
Normal file
18
utils/md5.go
Normal file
@ -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]
|
||||
}
|
Reference in New Issue
Block a user