🎇 直链url密码哈希
This commit is contained in:
@ -3,6 +3,7 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"github.com/Xhofe/alist/alidrive"
|
"github.com/Xhofe/alist/alidrive"
|
||||||
"github.com/Xhofe/alist/server/models"
|
"github.com/Xhofe/alist/server/models"
|
||||||
|
"github.com/Xhofe/alist/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -31,7 +32,7 @@ func Down(c *gin.Context) {
|
|||||||
c.JSON(200, MetaResponse(500, err.Error()))
|
c.JSON(200, MetaResponse(500, err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if fileModel.Password != "" && fileModel.Password != down.Password {
|
if fileModel.Password != "" && fileModel.Password != utils.Get16MD5Encode(down.Password) {
|
||||||
if down.Password == "" {
|
if down.Password == "" {
|
||||||
c.JSON(200, MetaResponse(401, "need password."))
|
c.JSON(200, MetaResponse(401, "need password."))
|
||||||
} else {
|
} else {
|
||||||
|
@ -2,6 +2,7 @@ package test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/Xhofe/alist/utils"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -25,3 +26,7 @@ func TestDir(t *testing.T) {
|
|||||||
dir,file:=filepath.Split("root")
|
dir,file:=filepath.Split("root")
|
||||||
fmt.Printf("dir:%s\nfile:%s\n",dir,file)
|
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