Compare commits

..

No commits in common. "cd376a0d00fb0f33a0bb0acd6a5706bbb832559d" and "bd7e36e98b17857885a45459b7f234777cf081d7" have entirely different histories.

View File

@ -173,23 +173,23 @@ func (s *PostgresStore) Query(query AttemptQuery) ([]models.LoginAttempt, error)
var stmt string var stmt string
queryString := query.Query queryString := query.Query
const limit = 10000
switch query.QueryType { switch query.QueryType {
case AttemptQueryTypeIP: case AttemptQueryTypeIP:
stmt = `SELECT id, date, remote_ip, username, password, client_version, connection_uuid, country stmt = `SELECT id, date, remote_ip, username, password, client_version, connection_uuid, country
FROM login_attempts WHERE remote_ip = $1 order by date desc limit $2` FROM login_attempts WHERE remote_ip = $1`
case AttemptQueryTypePassword: case AttemptQueryTypePassword:
stmt = `SELECT id, date, remote_ip, username, password, client_version, connection_uuid, country stmt = `SELECT id, date, remote_ip, username, password, client_version, connection_uuid, country
FROM login_attempts WHERE password = $1 order by date desc limit $2` FROM login_attempts WHERE password like $1`
queryString = fmt.Sprintf("%%%s%%", queryString)
case AttemptQueryTypeUsername: case AttemptQueryTypeUsername:
stmt = `SELECT id, date, remote_ip, username, password, client_version, connection_uuid, country stmt = `SELECT id, date, remote_ip, username, password, client_version, connection_uuid, country
FROM login_attempts WHERE username = $1 order by date desc limit $2` FROM login_attempts WHERE username like $1`
queryString = fmt.Sprintf("%%%s%%", queryString)
default: default:
return nil, fmt.Errorf("invalid query type") return nil, fmt.Errorf("invalid query type")
} }
rows, err := s.db.Query(stmt, queryString, limit) rows, err := s.db.Query(stmt, queryString)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to query database: %w", err) return nil, fmt.Errorf("unable to query database: %w", err)
} }
@ -204,6 +204,7 @@ func (s *PostgresStore) Query(query AttemptQuery) ([]models.LoginAttempt, error)
} }
la.RemoteIP = net.ParseIP(ipString) la.RemoteIP = net.ParseIP(ipString)
results = append(results, la) results = append(results, la)
} }
return results, nil return results, nil