Exemplo n.º 1
0
func (p *Token) Check(c server.ClientAuth) bool {
	opts := c.GetOpts()
	if p.Token != opts.Authorization {
		return false
	}

	return true
}
Exemplo n.º 2
0
func (p *Plain) Check(c server.ClientAuth) bool {
	opts := c.GetOpts()
	if p.Username != opts.Username || p.Password != opts.Password {
		return false
	}

	return true
}
Exemplo n.º 3
0
// Check authenticates a client from a token
func (p *Token) Check(c server.ClientAuth) bool {
	opts := c.GetOpts()
	// Check to see if the token is a bcrypt hash
	if isBcrypt(p.Token) {
		if err := bcrypt.CompareHashAndPassword([]byte(p.Token), []byte(opts.Authorization)); err != nil {
			return false
		}
	} else if p.Token != opts.Authorization {
		return false
	}

	return true
}
Exemplo n.º 4
0
// Check authenticates the client using a username and password against a list of multiple users.
func (m *MultiUser) Check(c server.ClientAuth) bool {
	opts := c.GetOpts()
	pass, ok := m.users[opts.Username]
	if !ok {
		return false
	}
	// Check to see if the password is a bcrypt hash
	if isBcrypt(pass) {
		if err := bcrypt.CompareHashAndPassword([]byte(pass), []byte(opts.Password)); err != nil {
			return false
		}
	} else if pass != opts.Password {
		return false
	}
	return true
}
Exemplo n.º 5
0
// Check authenticates the client using a username and password
func (p *Plain) Check(c server.ClientAuth) bool {
	opts := c.GetOpts()
	if p.Username != opts.Username {
		return false
	}
	// Check to see if the password is a bcrypt hash
	if isBcrypt(p.Password) {
		if err := bcrypt.CompareHashAndPassword([]byte(p.Password), []byte(opts.Password)); err != nil {
			return false
		}
	} else if p.Password != opts.Password {
		return false
	}

	return true
}