Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package main
import (
"fmt"
"net/http"
"regexp"
)
func loginHandler(w http.ResponseWriter, r *http.Request) {
username := r.FormValue("username")
valid := regexp.MustCompile(`^[a-zA-Z0-9_]{3,20}$`)
if !valid.MatchString(username) {
http.Error(w, "Invalid input", http.StatusBadRequest)
return
}
fmt.Fprintf(w, "Welcome %s", username)
}
func main() {
http.HandleFunc("/login", loginHandler)
fmt.Println("Secure application listening on :8080")
http.ListenAndServe(":8080", nil)
}Coding works best on desktop or with an external keyboard.