verify time limit code
(data string, minutes int, code string)
| 60 | |
| 61 | // verify time limit code |
| 62 | func 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 | |
| 88 | const TimeLimitCodeLength = 12 + 6 + 40 |
| 89 |