MCPcopy Create free account
hub / github.com/gogs/gogs / CreateTimeLimitCode

Function CreateTimeLimitCode

internal/tool/tool.go:92–119  ·  view source on GitHub ↗

CreateTimeLimitCode generates a time limit code based on given input data. Format: 12 length date time string + 6 minutes string + 40 sha1 encoded string

(data string, minutes int, startInf any)

Source from the content-addressed store, hash-verified

90// CreateTimeLimitCode generates a time limit code based on given input data.
91// Format: 12 length date time string + 6 minutes string + 40 sha1 encoded string
92func CreateTimeLimitCode(data string, minutes int, startInf any) string {
93 format := "200601021504"
94
95 var start, end time.Time
96 var startStr, endStr string
97
98 if startInf == nil {
99 // Use now time create code
100 start = time.Now()
101 startStr = start.Format(format)
102 } else {
103 // use start string create code
104 startStr = startInf.(string)
105 start, _ = time.ParseInLocation(format, startStr, time.Local)
106 startStr = start.Format(format)
107 }
108
109 end = start.Add(time.Minute * time.Duration(minutes))
110 endStr = end.Format(format)
111
112 // create sha1 encode string
113 sh := sha1.New()
114 _, _ = sh.Write([]byte(data + conf.Security.SecretKey + startStr + endStr + com.ToStr(minutes)))
115 encoded := hex.EncodeToString(sh.Sum(nil))
116
117 code := fmt.Sprintf("%s%06d%s", startStr, minutes, encoded)
118 return code
119}
120
121// HashEmail hashes email address to MD5 string.
122// https://en.gravatar.com/site/implement/hash/

Callers 2

VerifyTimeLimitCodeFunction · 0.85

Calls 2

AddMethod · 0.80
WriteMethod · 0.80

Tested by

no test coverage detected