diff --git a/auth.go b/auth.go index 1b22c33..ddd26a0 100644 --- a/auth.go +++ b/auth.go @@ -77,16 +77,16 @@ func usePassword(user string, pass string, ip string) bool { log.LogInfo("%+v", toks) tok := toks[user] delete(toks, user) - if time.Since(tok.timestamp) > (time.Minute * 5) { - log.LogWarn(fmt.Sprintf("%s attempted to use expired token. %+v", user, time.Since(tok.timestamp))) + if time.Since(tok.Timestamp) > (time.Minute * 5) { + log.LogWarn(fmt.Sprintf("%s attempted to use expired token. %+v", user, time.Since(tok.Timestamp))) return false } - if tok.ip != ip { + if tok.IP != ip { log.LogWarn(fmt.Sprintf("%s attempted to use an improper IP.", user)) return false } - if tok.password != pass { - log.LogWarn(fmt.Sprintf("%s attempted to use an improper password. %s vs %s", user, tok.password, pass)) + if tok.Password != pass { + log.LogWarn(fmt.Sprintf("%s attempted to use an improper password. %s vs %s", user, tok.Password, pass)) return false } @@ -113,11 +113,11 @@ func sendPassword(user string, ipaddr string) { if err != nil { log.LogErrorType(err) } - toks[m.User.Username] = tokens{ - username: user, - ip: ipaddr, - password: str, - timestamp: time.Now(), + toks[m.Nick] = Tokens{ + Username: user, + IP: ipaddr, + Password: str, + Timestamp: time.Now(), } pmChann, err := dg.UserChannelCreate(user) if err != nil { diff --git a/site-api.go b/site-api.go index 9e1d93c..8c123a5 100644 --- a/site-api.go +++ b/site-api.go @@ -14,7 +14,7 @@ import ( var ( store = sessions.NewCookieStore([]byte(os.Getenv("SESSION_KEY"))) - toks = make(map[string]tokens) + toks = make(map[string]Tokens) acctLinks = make(map[string]linkedAccount) ) diff --git a/types.go b/types.go index 1fdcad6..1e46db0 100644 --- a/types.go +++ b/types.go @@ -41,9 +41,10 @@ type linkedAccount struct { sigHash string } -type tokens struct { - username string - ip string - password string - timestamp time.Time +// Tokens are the Login Token struct +type Tokens struct { + Username string + IP string + Password string + Timestamp time.Time }