Skip to content

Commit

Permalink
Add new methods for setting and checking a potential server password
Browse files Browse the repository at this point in the history
  • Loading branch information
olabiniV2 committed Mar 26, 2020
1 parent dd9b553 commit b076a99
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/grumble/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,16 @@ func (server *Server) setConfigPassword(key, password string) {
}
}

// Set password as the new SuperUser password
// SetSuperUserPassword sets password as the new SuperUser password
func (server *Server) SetSuperUserPassword(password string) {
server.setConfigPassword("SuperUserPassword", password)
}

// SetServerPassword sets password as the new Server password
func (server *Server) SetServerPassword(password string) {
server.setConfigPassword("ServerPassword", password)
}

func (server *Server) checkConfigPassword(key, password string) bool {
parts := strings.Split(server.cfg.StringValue(key), "$")
if len(parts) != 3 {
Expand Down Expand Up @@ -246,6 +251,11 @@ func (server *Server) CheckSuperUserPassword(password string) bool {
return server.checkConfigPassword("SuperUserPassword", password)
}

// CheckServerPassword checks whether password matches the set Server password.
func (server *Server) CheckServerPassword(password string) bool {
return server.checkConfigPassword("ServerPassword", password)
}

// Called by the server to initiate a new client connection.
func (server *Server) handleIncomingClient(conn net.Conn) (err error) {
client := new(Client)
Expand Down

0 comments on commit b076a99

Please sign in to comment.