Compare commits

..

No commits in common. "82a4cde8c9374d046a5440c11879e1e12a50c780" and "bc90015a33a50b31533d1b9815680d7672a21cda" have entirely different histories.

View file

@ -283,7 +283,7 @@ func loginHandler(app *model.AppState) http.Handler {
err = bcrypt.CompareHashAndPassword([]byte(account.Password), []byte(password)) err = bcrypt.CompareHashAndPassword([]byte(account.Password), []byte(password))
if err != nil { if err != nil {
app.Log.Warn(log.TYPE_ACCOUNT, "\"%s\" attempted login with incorrect password. (%s)", account.Username, controller.ResolveIP(app, r)) app.Log.Warn(log.TYPE_ACCOUNT, "\"%s\" attempted login with incorrect password. (%s)", account.Username, controller.ResolveIP(app, r))
if locked := handleFailedLogin(app, account, r); locked { if locked := handleFailedLogin(app, account); locked {
controller.SetSessionError(app.DB, session, "Too many failed attempts. This account is now locked.") controller.SetSessionError(app.DB, session, "Too many failed attempts. This account is now locked.")
} else { } else {
controller.SetSessionError(app.DB, session, "Invalid username or password.") controller.SetSessionError(app.DB, session, "Invalid username or password.")
@ -389,7 +389,7 @@ func loginTOTPHandler(app *model.AppState) http.Handler {
} }
if totpMethod == nil { if totpMethod == nil {
app.Log.Warn(log.TYPE_ACCOUNT, "\"%s\" failed login (Incorrect TOTP). (%s)", session.AttemptAccount.Username, controller.ResolveIP(app, r)) app.Log.Warn(log.TYPE_ACCOUNT, "\"%s\" failed login (Incorrect TOTP). (%s)", session.AttemptAccount.Username, controller.ResolveIP(app, r))
if locked := handleFailedLogin(app, session.AttemptAccount, r); locked { if locked := handleFailedLogin(app, session.AttemptAccount); locked {
controller.SetSessionError(app.DB, session, "Too many failed attempts. This account is now locked.") controller.SetSessionError(app.DB, session, "Too many failed attempts. This account is now locked.")
controller.SetSessionAttemptAccount(app.DB, session, nil) controller.SetSessionAttemptAccount(app.DB, session, nil)
http.Redirect(w, r, "/admin", http.StatusFound) http.Redirect(w, r, "/admin", http.StatusFound)
@ -514,7 +514,7 @@ func enforceSession(app *model.AppState, next http.Handler) http.Handler {
}) })
} }
func handleFailedLogin(app *model.AppState, account *model.Account, r *http.Request) bool { func handleFailedLogin(app *model.AppState, account *model.Account) bool {
locked, err := controller.IncrementAccountFails(app.DB, account.ID) locked, err := controller.IncrementAccountFails(app.DB, account.ID)
if err != nil { if err != nil {
fmt.Fprintf( fmt.Fprintf(
@ -532,10 +532,9 @@ func handleFailedLogin(app *model.AppState, account *model.Account, r *http.Requ
if locked { if locked {
app.Log.Warn( app.Log.Warn(
log.TYPE_ACCOUNT, log.TYPE_ACCOUNT,
"Account \"%s\" was locked: %d failed login attempts (IP: %s)", "Account \"%s\" was locked: %d failed login attempts",
account.Username, account.Username,
model.MAX_LOGIN_FAIL_ATTEMPTS, model.MAX_LOGIN_FAIL_ATTEMPTS,
controller.ResolveIP(app, r),
) )
} }
return locked return locked