package main
import (
"bufio"
"fmt"
"net"
"strings"
)
type User struct {
Password string
Role string
}
var users = map[string]User{
"admin": {"admin123", "Admin"},
"user1": {"user123", "User"},
}
func handleConnection(conn net.Conn) {
defer conn.Close()
reader := bufio.NewReader(conn)
username, _ := reader.ReadString('\n')
username = strings.TrimSpace(username)
password, _ := reader.ReadString('\n')
password = strings.TrimSpace(password)
user, exists := users[username]
if exists && user.Password == password {
response := "Login Successful! Role: " + user.Role + "\n"
conn.Write([]byte(response))
} else {
conn.Write([]byte("Invalid Credentials\n"))
}
}
func main() {
listener, err := net.Listen("tcp", ":8080")
if err != nil {
fmt.Println("Error:", err)
return
}
defer listener.Close()
fmt.Println("Server started on port 8080...")
for {
conn, err := listener.Accept()
if err != nil {
fmt.Println("Connection Error:", err)
continue
}
go handleConnection(conn)
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: