MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / LoginFromRequest

Method LoginFromRequest

internal/auth/auth.go:198–222  ·  view source on GitHub ↗

LoginFromRequest 供面板 handler 调用,携带 IP 用于暴力破解防护。

(r *http.Request, username, password string)

Source from the content-addressed store, hash-verified

196
197// LoginFromRequest 供面板 handler 调用,携带 IP 用于暴力破解防护。
198func (m *Manager) LoginFromRequest(r *http.Request, username, password string) (string, error) {
199 ip := clientIP(r)
200 if m.isLocked(ip) {
201 return "", errors.New("too many failed attempts, try later")
202 }
203 _, adminUsername, hash, ok := m.adminStore.GetAdminUser()
204 if !ok || username != adminUsername {
205 m.recordFailure(ip)
206 return "", errors.New("invalid credentials")
207 }
208 if len(password) > 72 {
209 m.recordFailure(ip)
210 return "", errors.New("invalid credentials")
211 }
212 if err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)); err != nil {
213 m.recordFailure(ip)
214 return "", errors.New("invalid credentials")
215 }
216 m.clearFailures(ip)
217 token := randomToken()
218 if err := m.sessions.Create(token, username); err != nil {
219 return "", err
220 }
221 return token, nil
222}
223
224// CreateSession 直接为指定用户名创建 session,供 Discourse SSO 等第三方认证使用。
225func (m *Manager) CreateSession(username string) (string, error) {

Callers

nothing calls this directly

Calls 7

isLockedMethod · 0.95
recordFailureMethod · 0.95
clearFailuresMethod · 0.95
clientIPFunction · 0.70
randomTokenFunction · 0.70
GetAdminUserMethod · 0.65
CreateMethod · 0.65

Tested by

no test coverage detected