liveBook · Manning

Failed login attempt

As explained in Data-Driven Cybersecurity

A failed login attempt is an unsuccessful effort to authenticate to an account or system.

A failed login attempt is an unsuccessful effort to authenticate to an account or system. Counting attempts helps monitor access-control risk, but the count is most useful alongside information about when, where, and why logins failed. Failed logins are one of the data points used to assess security posture against SOC 2-related objectives. section 3.3.1 section 13.6.2

Turn the count into an investigation:

  • Group failures by reason, user, login hour, and device type. A frequent incorrect-password result may warrant password-practice training; mobile invalid-credentials errors may warrant a review of mobile login procedures. section 13.6.2
  • Check whether failures cluster at particular hours or precede access-control violations. Review affected users, departments, and any attempted breaches during the same period. section 13.6.2 section 3.4.2
  • Prioritize by context rather than volume alone: frequent failures can suggest a possible brute-force attack or poor password practices. section 13.8.1

From alert to executive action

In one incident, multiple failed logins preceded unauthorized access to restricted patient data. The access-management tool flagged the behavior, but an access-control configuration error and delayed escalation contributed to the incident. A useful report connects the login signal to the violation, response delay, corrective actions, and results—not just the number of failures. section 3.4.2

Listing 13.2 Generating synthetic data for failed logins
# Import required libraries
from openai import OpenAI  #1
import pandas as pd   #1
import matplotlib.pyplot as plt   #1
import json   #1

# Configure LM Studio client
client = OpenAI(base_url="http://localhost:1234/v1",
                api_key="lm-studio")  #2

# Define system message for strict JSON formatting
system_message = {
    "role": "system",
    "content": (
        "You are a JSON data generator. Respond only with valid JSON data. "
        "Do not include any additional text, comments, or explanations."
    )
}  #3

# User prompt for generating data
user_message = {
    "role": "user",
    "content": (
        "Generate JSON data representing failed login attempts with "
        "the following fields:\\n"
        "- 'User ID': A unique identifier for the user (e.g., 'U001').\n"
        "- 'Login Hour': The hour of login in 24-hour format "
        "(e.g., 13 for 1 PM).\\n"
        "- 'Device Type': The device used for login "
        "(e.g., 'Laptop', 'Mobile').\\n"
        "- 'Failed Login Reason': The reason for the failed login "
        "(e.g., 'Incorrect Password').\\n"
        "Generate 20 records in JSON format."
    )
}  #3

# Request AI-generated JSON data
response = client.chat.completions.create(  #4
    model="LM Studio Community/Meta-Llama-3-8B-Instruct-GGUF",   #4
    messages=[system_message, user_message],   #4
    temperature=0.7,   #4
)

# Process the AI response
try:
    raw_response = (
        response.choices[0].message.content.strip()  #5
 #5
) #5
    print("Raw AI Response:\n", raw_response)   #5

    # Parse the JSON data
    json_data = json.loads(raw_response)  #6
    data = pd.DataFrame(json_data)   #6
except json.JSONDecodeError as e:
    print("Error decoding JSON:", e)  #7
    print("Raw response for debugging:", raw_response)   #7
    exit() #7
except Exception as e: #7
    print("Unexpected error:", e)   #7
    exit()

# Debugging: Print the DataFrame to verify structure
print("Generated DataFrame:\n", data.head())  #8

# Check for expected columns
if "Failed Login Reason" not in data.columns:  #9
    print("The column 'Failed Login Reason' is missing. " #9
          "Check the generated data.")   #9
    exit()

# Analyze the data
failed_login_counts = data. \
    groupby("Failed Login Reason").size()  #10

# Visualize the analysis
plt.figure(figsize=(8, 6))  #11
failed_login_counts.plot(kind="bar", color="gray")   #11
plt.title("Failed Login Reasons")   #11
plt.xlabel("Reason")   #11
plt.ylabel("Count")   #11
plt.grid(axis="y", linestyle="--")   #11
plt.show()   #11

A Python listing uses LM Studio to generate fictitious failed-login records for safe analysis. Fields include user ID, login hour, device type, and failure reason; a chart makes the most common reasons visible. Treat synthetic patterns as practice data, not evidence of actual organizational risk. section 13.6.1

How Data-Driven Cybersecurity covers it

How deep it goes
Shows how to categorize, chart, interpret, and report failures, without specifying a formal alert threshold.
Examples
Uses a patient-data access incident and a synthetic dataset grouped by failure reason, device, and hour.
What you can do after
Evaluate/understand failed-login patterns and turn them into targeted investigation and monitoring recommendations.
How it connects
Links failed logins to access control violations, incident response, password practices, and account lockout policies.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Driven Cybersecurity. The section links point to the parts of the book it draws on.