{"id":21296884,"url":"https://github.com/reddec/go-login","last_synced_at":"2025-03-15T17:27:28.842Z","repository":{"id":65331850,"uuid":"588219561","full_name":"reddec/go-login","owner":"reddec","description":"Golang login page","archived":false,"fork":false,"pushed_at":"2023-01-12T16:09:49.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-09T00:06:49.031Z","etag":null,"topics":["csrf","generics","login-page","owasp"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reddec.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-12T15:58:05.000Z","updated_at":"2024-06-09T11:36:06.000Z","dependencies_parsed_at":"2023-02-09T12:45:31.597Z","dependency_job_id":null,"html_url":"https://github.com/reddec/go-login","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fgo-login","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fgo-login/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fgo-login/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fgo-login/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reddec","download_url":"https://codeload.github.com/reddec/go-login/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243764930,"owners_count":20344502,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csrf","generics","login-page","owasp"],"created_at":"2024-11-21T14:30:21.635Z","updated_at":"2025-03-15T17:27:28.798Z","avatar_url":"https://github.com/reddec.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-login\n\n[![license](https://img.shields.io/github/license/reddec/go-login.svg)](https://github.com/reddec/go-login)\n[![](https://godoc.org/github.com/reddec/go-login?status.svg)](http://godoc.org/github.com/reddec/go-login)\n\nGo handler for login pages with configurable fields.\n\n- Zero-dependencies\n- Type-safe configuration (Go generics)\n- CSRF protection by-default\n- Works well with any HTTP frameworks\n- Default minimalistic, mobile-friendly login page\n\n\nExample\n\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"net/http\"\n\n\tlogin \"githun.com/reddec/go-login\"\n)\n\nfunc loginFunc(writer http.ResponseWriter, r *http.Request, cred login.UserPassword) error {\n\tok := cred.User == \"admin\" \u0026\u0026 cred.Password == \"admin\" // user proper login and validation\n\tif !ok {\n\t\treturn fmt.Errorf(\"username or password is incorrect\")\n\t}\n\t// use sessions/JWT/cookies and mark following requests as authorized\n\treturn nil\n}\n\nfunc main() {\n\thttp.HandleFunc(\"/\", func(writer http.ResponseWriter, request *http.Request) {\n\t\twriter.Write([]byte(\"\u003chtml\u003e\u003cbody\u003e\u003ch1\u003eHome\u003c/h1\u003e\u003cbr/\u003e\u003ca href='/login'\u003eLogin\u003c/a\u003e\u003c/body\u003e\u003c/html\u003e\"))\n\t})\n\thttp.Handle(\"/login\", login.New[login.UserPassword](loginFunc, login.Log(func(err error) {\n\t\tlog.Println(err)\n\t})))\n\tpanic(http.ListenAndServe(\"127.0.0.1:8080\", nil))\n}\n```\n\n\u003cimg width=\"407\" alt=\"image\" src=\"https://user-images.githubusercontent.com/6597086/212119984-bee69f07-c4ba-46f4-9186-c022f25506bf.png\"\u003e\n\n\n\n## Custom form\n\nUse annotations on string fields:\n\n- `title` for form labels\n- `placeholder` for input placeholders\n- `hidden` to mark input as hidden (password)\n\n```go\ntype DomainLogin struct {\n\tDomain   string `title:\"Domain name\" placeholder:\"domain or company\"`\n\tUser     string `title:\"Username\" placeholder:\"enter username\"`\n\tPassword string `title:\"Password\" placeholder:\"enter password\" hidden:\"true\"`\n}\n\n```\n\nand handle it as normal\n\n```go\n\nfunc loginFunc(writer http.ResponseWriter, r *http.Request, cred DomainLogin) error {\n\t// ...\n\treturn nil\n}\n\nfunc main() {\n\t// ...\n\thttp.Handle(\"/login\", login.New[DomainLogin](loginFunc))\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freddec%2Fgo-login","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freddec%2Fgo-login","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freddec%2Fgo-login/lists"}