Handle passwords serverside
This commit is contained in:
parent
8cb40303dc
commit
99923c64b1
|
@ -15,6 +15,7 @@ import (
|
|||
|
||||
var (
|
||||
listenPort string = "1302"
|
||||
password string = ""
|
||||
isLogging bool = false
|
||||
logLocation string
|
||||
listenerList []chan string
|
||||
|
@ -92,9 +93,31 @@ func populateChat(conn net.Conn) {
|
|||
|
||||
}
|
||||
|
||||
func getPasswd(conn net.Conn) error {
|
||||
conn.Write([]byte("Password: "))
|
||||
userPassNewline, err := bufio.NewReader(conn).ReadString('\n')
|
||||
userPass := strings.TrimRight(userPassNewline, "\n")
|
||||
if err != nil {
|
||||
e := fmt.Errorf("Node %v didn't respond to password prompt!\n", getIP(conn))
|
||||
return e
|
||||
}
|
||||
if userPass != password {
|
||||
e := fmt.Errorf("Node %v attempted connecting with an incorrect password!\n", getIP(conn))
|
||||
return e
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleConn(conn net.Conn, chatChan chan string) {
|
||||
defer conn.Close()
|
||||
|
||||
if password != "" {
|
||||
if err := getPasswd(conn); err != nil {
|
||||
log.Print(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
go receiveMessageServer(conn, chatChan)
|
||||
|
||||
//////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue