diff options
author | Joe Chen <jc@unknwon.io> | 2022-11-27 15:19:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-27 15:19:44 +0800 |
commit | 13099a7e4fe7565bb858646d42d1fba817cb06cc (patch) | |
tree | ac932d0f5df9f14b0f9408c32f699ae7167edc25 /internal/tool | |
parent | a7dbc970dfaac9f04addf05da97bb0aa29083e37 (diff) |
refactor(db): add `Users.Update` (#7263)
Diffstat (limited to 'internal/tool')
-rw-r--r-- | internal/tool/tool.go | 16 |
1 files changed, 2 insertions, 14 deletions
diff --git a/internal/tool/tool.go b/internal/tool/tool.go index e4280b2a..bc6dda11 100644 --- a/internal/tool/tool.go +++ b/internal/tool/tool.go @@ -5,7 +5,6 @@ package tool import ( - "crypto/md5" "crypto/sha1" "encoding/base64" "encoding/hex" @@ -23,6 +22,7 @@ import ( "github.com/gogs/chardet" "gogs.io/gogs/internal/conf" + "gogs.io/gogs/internal/cryptoutil" ) // ShortSHA1 truncates SHA1 string length to at most 10. @@ -125,10 +125,7 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string // HashEmail hashes email address to MD5 string. // https://en.gravatar.com/site/implement/hash/ func HashEmail(email string) string { - email = strings.ToLower(strings.TrimSpace(email)) - h := md5.New() - _, _ = h.Write([]byte(email)) - return hex.EncodeToString(h.Sum(nil)) + return cryptoutil.MD5(strings.ToLower(strings.TrimSpace(email))) } // AvatarLink returns relative avatar link to the site domain by given email, @@ -358,15 +355,6 @@ func Subtract(left, right interface{}) interface{} { } } -// TruncateString returns a truncated string with given limit, -// it returns input string if length is not reached limit. -func TruncateString(str string, limit int) string { - if len(str) < limit { - return str - } - return str[:limit] -} - // StringsToInt64s converts a slice of string to a slice of int64. func StringsToInt64s(strs []string) []int64 { ints := make([]int64, len(strs)) |