Browse Source

Authy

hkremer/rebranding
Gregory Rudolph 4 years ago
parent
commit
0a2dc22837
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
  1. 20
      auth.go
  2. 2
      site-api.go
  3. 11
      types.go

20
auth.go

@ -77,16 +77,16 @@ func usePassword(user string, pass string, ip string) bool {
log.LogInfo("%+v", toks) log.LogInfo("%+v", toks)
tok := toks[user] tok := toks[user]
delete(toks, user) delete(toks, user)
if time.Since(tok.timestamp) > (time.Minute * 5) { if time.Since(tok.Timestamp) > (time.Minute * 5) {
log.LogWarn(fmt.Sprintf("%s attempted to use expired token. %+v", user, time.Since(tok.timestamp))) log.LogWarn(fmt.Sprintf("%s attempted to use expired token. %+v", user, time.Since(tok.Timestamp)))
return false return false
} }
if tok.ip != ip { if tok.IP != ip {
log.LogWarn(fmt.Sprintf("%s attempted to use an improper IP.", user)) log.LogWarn(fmt.Sprintf("%s attempted to use an improper IP.", user))
return false return false
} }
if 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)) log.LogWarn(fmt.Sprintf("%s attempted to use an improper password. %s vs %s", user, tok.Password, pass))
return false return false
} }
@ -113,11 +113,11 @@ func sendPassword(user string, ipaddr string) {
if err != nil { if err != nil {
log.LogErrorType(err) log.LogErrorType(err)
} }
toks[m.User.Username] = tokens{ toks[m.Nick] = Tokens{
username: user, Username: user,
ip: ipaddr, IP: ipaddr,
password: str, Password: str,
timestamp: time.Now(), Timestamp: time.Now(),
} }
pmChann, err := dg.UserChannelCreate(user) pmChann, err := dg.UserChannelCreate(user)
if err != nil { if err != nil {

2
site-api.go

@ -14,7 +14,7 @@ import (
var ( var (
store = sessions.NewCookieStore([]byte(os.Getenv("SESSION_KEY"))) store = sessions.NewCookieStore([]byte(os.Getenv("SESSION_KEY")))
toks = make(map[string]tokens) toks = make(map[string]Tokens)
acctLinks = make(map[string]linkedAccount) acctLinks = make(map[string]linkedAccount)
) )

11
types.go

@ -41,9 +41,10 @@ type linkedAccount struct {
sigHash string sigHash string
} }
type tokens struct { // Tokens are the Login Token struct
username string type Tokens struct {
ip string Username string
password string IP string
timestamp time.Time Password string
Timestamp time.Time
} }

Loading…
Cancel
Save