func HandleAuthenticationRequest(username string, password string, connection net.Conn) (err error) {
	var messageType byte
	var message []byte
	if messageType, message, err = ReadMessage(connection); err != nil {
		return
	}
	if messageType == ErrorMessageType {
		err = NewError(message)
		return
	}
	if messageType != AuthenticationMessageType {
		err = fmt.Errorf("Expected %d message type, got %d", AuthenticationMessageType, messageType)
		return
	}
	var authType int32
	reader := bytes.NewReader(message)
	if err = binary.Read(reader, binary.BigEndian, &authType); err != nil {
		return
	}
	switch authType {
	case AuthenticationClearText:
		return handleAuthClearText(password, connection)
	case AuthenticationMD5:
		salt := make([]byte, 4)
		if _, err = io.ReadFull(reader, salt); err != nil {
			return
		}
		return handleAuthMD5(username, password, string(salt), connection)
	case AuthenticationOk:
		return
	}
	err = fmt.Errorf("Authentication method %d is not supported", authType)
	return
}
HandleAuthenticationRequest sends credentials to the server and reports whether they were accepted or not.
package protocol
import (
	"bytes"
	"crypto/md5"
	"encoding/binary"
	"fmt"
	"io"
	"net"
)