package main import ( "crypto/rand" "fmt" "log" "net/http" ) const ( passwordLength = 32 chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" //chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!?$%&=#+<>-:,.;_*@" ) func generatePassword() string { password := make([]byte, passwordLength) _, err := rand.Read(password) if err != nil { log.Fatal(err) } for i := 0; i < passwordLength; i++ { password[i] = chars[int(password[i])%len(chars)] } return string(password) } func passwordHandler(w http.ResponseWriter, r *http.Request) { password := generatePassword() fmt.Fprint(w, password) } func helpHandler(w http.ResponseWriter, r *http.Request) { helpHTML := `
Diese Anwendung bietet einen API-Endpunkt, um Passwörter direkt über die Kommandozeile abzurufen. Der Endpunkt gibt das Passwort im Plain-Text-Format zurück.
http://localhost:8080/api/password
echo $(curl -s http://localhost:8080/api/password)
Invoke-RestMethod -Uri http://localhost:8080/api/password
curl http://localhost:8080/api/password