diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-26 08:58:34 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-26 08:58:34 (GMT) |
commit | e2dee26e41817302ed4e14207ce779d58004f797 (patch) | |
tree | 1c472734f4bac38856d070a45ae979101af1c6d2 | |
parent | 7f63f817486684c0dcb440bf57ff79c07c487911 (diff) |
session store now checks password
-rw-r--r-- | fetcher.go | 31 | ||||
-rw-r--r-- | rddb.go | 27 | ||||
-rw-r--r-- | session_store.go | 10 |
3 files changed, 43 insertions, 25 deletions
@@ -247,31 +247,14 @@ func fetcher_init() { } func checkPassword(ctx *ImportContext, result *FetchResult) (err error) { - cached := true - - for { - res_ch := make(chan getPasswordResult) - req := getPasswordRequest{} - req.username = ctx.UserName - req.cached = cached - req.response = res_ch - ctx.rddb.getPasswordChan <- req - - res := <-res_ch - if res.err != nil { - return res.err - } - if ctx.Password == res.password { - return nil - } - if cached { - cached = false - } else { - break - } + ok := false + if ok, err = ctx.rddb.CheckPassword(ctx.UserName, ctx.Password); err != nil { + return + } + if !ok { + result.ResponseCode = http.StatusUnauthorized + result.ErrorString = "invalid username and/or password" } - result.ResponseCode = http.StatusUnauthorized - result.ErrorString = "invalid username and/or password" return } @@ -177,6 +177,33 @@ func (self *RdDb) getPassword(username string, cached bool) (result getPasswordR return } +func (self *RdDbChan) CheckPassword(username, password string) (result bool, err error) { + cached := true + + for { + res_ch := make(chan getPasswordResult) + req := getPasswordRequest{} + req.username = username + req.cached = cached + req.response = res_ch + self.getPasswordChan <- req + + res := <-res_ch + if res.err != nil { + return false, res.err + } + if password == res.password { + return true, nil + } + if cached { + cached = false + } else { + break + } + } + return false, nil +} + func (self *RdDb) getGroupOfCart(cart uint) (result getGroupOfCartResult) { var rows *sql.Rows if rows, result.err = self.getGroupOfCartStmt.Query(cart, cart); result.err != nil { diff --git a/session_store.go b/session_store.go index 2aabc44..e065182 100644 --- a/session_store.go +++ b/session_store.go @@ -79,7 +79,15 @@ type SessionStore struct { } func (self *SessionStore) new(ctx *ImportContext) (resp newSessionResponse) { - // TODO: for untrusted interfaces we need to check Username and PassWord!!!! + if !ctx.Trusted { + if ok, err := ctx.rddb.CheckPassword(ctx.UserName, ctx.Password); err != nil { + resp.err = err + return + } else if !ok { + resp.err = fmt.Errorf("invalid username and/or password") + return + } + } b := uuid.NewV4().Bytes() resp.id = strings.ToLower(strings.TrimRight(base32.StdEncoding.EncodeToString(b), "=")) if _, exists := self.store[ctx.UserName]; !exists { |