https://github.com/bddjr/basiclogin-gin
为Cookie设计的轻量级登录框架。Lightweight login framework designed for cookie.
https://github.com/bddjr/basiclogin-gin
gin go golang httpserver login
Last synced: 11 months ago
JSON representation
为Cookie设计的轻量级登录框架。Lightweight login framework designed for cookie.
- Host: GitHub
- URL: https://github.com/bddjr/basiclogin-gin
- Owner: bddjr
- License: bsd-3-clause
- Archived: true
- Created: 2024-07-03T15:10:58.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-09T06:46:04.000Z (over 1 year ago)
- Last Synced: 2025-03-12T03:43:37.178Z (about 1 year ago)
- Topics: gin, go, golang, httpserver, login
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Warning
不建议使用,它不能记住密码。而且它会导致Firefox在不关闭浏览器的情况下无法安全退出登录。
It is not recommended to use it, as it does not remember passwords and it can cause Firefox to be unable to securely log out without closing the browser.
# basiclogin-gin
为Cookie设计的轻量级登录框架,兼容chrome 、firefox浏览器,暂未测试safari浏览器。
Lightweight login framework designed for cookie, compatible with chrome, firefox, not tested safari.
Reference https://developer.mozilla.org/docs/Web/HTTP/Authentication
## Get
```
go get github.com/bddjr/basiclogin-gin
```
## Example
[See test/main.go](test/main.go)
```go
loginGroup := Router.Group("login")
basiclogin.New(loginGroup, func(ctx *gin.Context, username, password string, secure bool) {
// ⚠ If you need *http.Cookie, please use
// ctx.Writer.Header().Add("Set-Cookie", cookie.String())
if username == staticUserName && hmac.Equal([]byte(password), []byte(StaticPassword)) {
ctx.SetCookie(cookieName, cookieValue, 0, "/", "", secure, true)
ctx.Header("Referrer-Policy", "no-referrer")
basiclogin.ScriptRedirect(ctx, 401, "/")
return
}
ctx.String(401, "Wrong usename or password")
})
```
## License
[BSD-3-clause license](LICENSE.txt)