Add new methods for setting and checking a potential server password

This commit is contained in:
Ola Bini 2020-03-26 15:03:05 +00:00
parent dd9b5531a3
commit b076a99492
No known key found for this signature in database
GPG key ID: 6786A150F6A2B28F

View file

@ -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 {
@ -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)