1
0
Fork 0

Neater logic

master
Philip O'Toole 9 months ago
parent 5116b2f599
commit e06e7bea00

@ -107,10 +107,7 @@ func (c *CredentialsStore) Load(r io.Reader) error {
// Check returns true if the password is correct for the given username. // Check returns true if the password is correct for the given username.
func (c *CredentialsStore) Check(username, password string) bool { func (c *CredentialsStore) Check(username, password string) bool {
pw, ok := c.store[username] pw, ok := c.store[username]
if !ok { return ok && pw == password
return false
}
return password == pw
} }
// Password returns the password for the given user. // Password returns the password for the given user.
@ -174,12 +171,12 @@ func (c *CredentialsStore) AA(username, password, perm string) bool {
return true return true
} }
// At this point a username needs to have been supplied // At this point a username needs to have been supplied.
if username == "" { if username == "" {
return false return false
} }
// Are the creds good? // Authenticate the user.
if !c.Check(username, password) { if !c.Check(username, password) {
return false return false
} }
@ -193,8 +190,5 @@ func (c *CredentialsStore) AA(username, password, perm string) bool {
// in the request, it returns false. // in the request, it returns false.
func (c *CredentialsStore) HasPermRequest(b BasicAuther, perm string) bool { func (c *CredentialsStore) HasPermRequest(b BasicAuther, perm string) bool {
username, _, ok := b.BasicAuth() username, _, ok := b.BasicAuth()
if !ok { return ok && c.HasPerm(username, perm)
return false
}
return c.HasPerm(username, perm)
} }

Loading…
Cancel
Save