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

Function VerifyTimeLimitCode

internal/tool/tool.go:62–86  ·  view source on GitHub ↗

verify time limit code

(data string, minutes int, code string)

Source from the content-addressed store, hash-verified

60
61// verify time limit code
62func VerifyTimeLimitCode(data string, minutes int, code string) bool {
63 if len(code) <= 18 {
64 return false
65 }
66
67 // split code
68 start := code[:12]
69 lives := code[12:18]
70 if d, err := com.StrTo(lives).Int(); err == nil {
71 minutes = d
72 }
73
74 // right active code
75 retCode := CreateTimeLimitCode(data, minutes, start)
76 if retCode == code && minutes > 0 {
77 // check time is expired or not
78 before, _ := time.ParseInLocation("200601021504", start, time.Local)
79 now := time.Now()
80 if before.Add(time.Minute*time.Duration(minutes)).Unix() > now.Unix() {
81 return true
82 }
83 }
84
85 return false
86}
87
88const TimeLimitCodeLength = 12 + 6 + 40
89

Callers 3

verifyUserActiveCodeFunction · 0.92
verifyActiveEmailCodeFunction · 0.92
TestGenerateActivateCodeFunction · 0.92

Calls 2

CreateTimeLimitCodeFunction · 0.85
AddMethod · 0.80

Tested by 1

TestGenerateActivateCodeFunction · 0.74