Skip to content

Conversation

@SorynTech
Copy link
Owner

@SorynTech SorynTech commented Dec 17, 2025

Summary by CodeRabbit

  • New Features
    • Added admin control panel for managing user accounts with persistent data storage
    • Admins can now change usernames, view all registered users, and delete accounts
    • Enhanced admin authentication with retry attempt limits and automatic session handling

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 17, 2025

Walkthrough

Introduces a new admin workflow with persistent user management. Admin login now loops for credential validation with attempt counters. New functions load and save user data to persistent storage. Admin panel provides UI for managing users (change username, list users, delete user) triggered after successful authentication.

Changes

Cohort / File(s) Summary
Data Persistence Utilities
Backend user system/lgoin system.py
Added load_users() and save_users(users) functions to manage persistent user data storage via userdata.txt file
Admin Panel & User Management UI
Backend user system/lgoin system.py
Added adminpanel(), change_username(), see_all_users(), and delete_user() functions to provide admin interface for user management operations
Admin Authentication Flow
Backend user system/lgoin system.py
Modified admin login logic to use repeated credential validation loops with attempt counter, triggering fallback on max attempts; integrated adminpanel invocation after successful admin authentication and password attempt reset

Sequence Diagram

sequenceDiagram
    actor Admin
    participant AuthSystem as Authentication
    participant AdminPanel as Admin Panel
    participant FileSystem as File Storage
    
    rect rgb(220, 240, 255)
    Note over Admin,FileSystem: Admin Login Flow
    Admin->>AuthSystem: Enter credentials
    AuthSystem->>AuthSystem: Validate credentials
    alt Credentials invalid
        AuthSystem->>Admin: Prompt retry
        Admin->>AuthSystem: Re-enter credentials
    else Credentials valid
        AuthSystem->>FileSystem: load_users()
        FileSystem-->>AuthSystem: User data
        AuthSystem->>AdminPanel: Trigger adminpanel
    end
    end
    
    rect rgb(240, 220, 255)
    Note over Admin,FileSystem: Admin Operations
    Admin->>AdminPanel: Select operation
    alt Change Username / Delete User
        AdminPanel->>FileSystem: load_users()
        FileSystem-->>AdminPanel: User data
        AdminPanel->>AdminPanel: Modify user(s)
        AdminPanel->>FileSystem: save_users(updated)
    else See All Users
        AdminPanel->>FileSystem: load_users()
        FileSystem-->>AdminPanel: User data
        AdminPanel->>Admin: Display users
    end
    end
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Admin authentication loop logic: Verify attempt counter implementation and fallback behavior work correctly
  • File I/O operations: Ensure load_users/save_users handle edge cases (missing file, corrupted data, file permissions)
  • Admin panel state management: Confirm user data persistence across multiple operations and error scenarios
  • Integration between components: Check that password attempt reset and adminpanel invocation integrate correctly with existing main flow

Poem

🐰 A tale of admins and their domain,
With files that remember and buttons that reign,
Load, save, and manage with care,
User credentials stored here and there—
The admin now reigns with persistent flair!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Added the Admin Panel' directly and specifically describes the main change in the pull request—the introduction of a new admin workflow with an adminpanel UI and related admin management functions.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch PRs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (1)
Backend user system/lgoin system.py (1)

157-170: Good extraction; consider refactoring existing functions to use it.

This helper consolidates the user loading logic. The same pattern is duplicated in signup() (lines 51-61) and login() (lines 104-111). Consider refactoring those functions to use load_users() for consistency.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5807405 and b2d1ff3.

📒 Files selected for processing (1)
  • Backend user system/lgoin system.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.14.8)
Backend user system/lgoin system.py

181-181: Local variable users is assigned to but never used

Remove assignment to unused variable users

(F841)

🔇 Additional comments (2)
Backend user system/lgoin system.py (2)

173-177: LGTM!

Good helper extraction. Consider using this in signup() (lines 90-92) to eliminate duplication.


236-274: LGTM!

Both see_all_users and delete_user are well-implemented with proper validation and user confirmation for destructive operations.

Comment on lines +140 to +152
while login_username != ADMIN_USER:
print("Invalid Username")
login_username = input("What is your Username: ")

return False
if login_password != Admin_password:
while login_password != Admin_password:
print("Invalid Password")
return False
passwordattempts = passwordattempts+1
print("Remaining Attempts:",passwordattempts)
if passwordattempts >= 3:
print("You are not an Admin Nice try")
main()
login_password = input("What is your Password: ")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical logic bug: return False executes inside the while loop.

The return False on line 144 is indented inside the while loop, causing the function to immediately return after the first invalid username attempt instead of allowing retry. Similarly, the password validation loop structure is problematic.

Additionally:

  • Line 148 shows "Remaining Attempts" but displays the count going up (0→1→2), which is confusing.
  • Line 151 uses recursive main() call which can cause stack overflow with repeated failures.

Apply this diff to fix the logic:

 def adminlogin():
     global passwordattempts
     login_username = input("What is your Username: ")
-    login_password = input("What is your Password: ")
 
     while login_username != ADMIN_USER:
         print("Invalid Username")
         login_username = input("What is your Username: ")
 
-        return False
+    login_password = input("What is your Password: ")
+    
     while login_password != Admin_password:
         print("Invalid Password")
-        passwordattempts = passwordattempts+1
-        print("Remaining Attempts:",passwordattempts)
+        passwordattempts += 1
+        print(f"Failed Attempts: {passwordattempts}/3")
         if passwordattempts >= 3:
             print("You are not an Admin Nice try")
-            main()
+            return False
         login_password = input("What is your Password: ")
 
     print("Welcome Admin")
     return True

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In Backend user system/lgoin system.py around lines 140 to 152, the username
loop currently returns False inside the while loop which causes an immediate
exit after the first invalid entry and the password loop increments attempts and
calls main() recursively; fix by removing the in-loop return so the username
while loop keeps prompting until a match (or exits after a controlled max
attempts), rework the password loop to decrement a remaining_attempts counter
(or calculate remaining as max_attempts - attempts) so the printed "Remaining
Attempts" counts down, and replace the recursive main() call with an iterative
control flow (e.g., break/continue to outer loop or return to caller) to avoid
recursion and possible stack overflow; ensure variable names (ADMIN_USER vs
Admin_password) are used consistently and move any final return False to after
loops when authentication fails.

Comment on lines +173 to +177
def save_users(users):
"""Save users to userdata.txt file"""
with open('userdata.txt', 'w') as f:
for username, password in users.items():
f.write(f"{username}:{password}\n")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Security: Passwords are stored in plaintext.

Both user credentials and this save function store passwords in plaintext. For any production use, passwords should be hashed using a secure algorithm like bcrypt or argon2.

Example using hashlib (for learning; prefer bcrypt for production):

import hashlib

def hash_password(password):
    return hashlib.sha256(password.encode()).hexdigest()

def save_users(users):
    """Save users to userdata.txt file (passwords should already be hashed)"""
    with open('userdata.txt', 'w') as f:
        for username, password_hash in users.items():
            f.write(f"{username}:{password_hash}\n")

Note: This would require updating signup() and login() to hash passwords during registration and verification.

🤖 Prompt for AI Agents
In Backend user system/lgoin system.py around lines 173 to 177, the save_users
function writes plaintext passwords to userdata.txt; change it to store password
hashes instead: update the signup flow to hash new passwords with a secure
algorithm (preferably bcrypt or argon2) and store the resulting hash in the
users dict, change login to verify incoming passwords against the stored hash
using the corresponding verify function, and modify save_users to write
username:password_hash lines (and load_users to expect hashes). Ensure you add
the chosen hashing library to dependencies and handle errors on read/write
consistently.

Comment on lines +180 to +205
def adminpanel():
users = load_users() # Load users at the start

Rabbit.sleep(1)
print("\n=== Admin Panel ===")
print("1: Change a Users Username")
print("2: See all users")
print("3: Delete a User account")
print("4: Exit Admin Panel")

choice = input("\nEnter your choice (1-4): ").strip()

if choice == "1":
change_username()
elif choice == "2":
see_all_users()
elif choice == "3":
delete_user()
elif choice == "4":
print("Exiting admin panel...")
main()
else:
print("Invalid choice. Please try again.")

# Loop back to admin panel
adminpanel()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Control flow issues and unused variable.

  1. Line 181: users is loaded but never used (as flagged by static analysis).
  2. Lines 200 + 205: When user chooses "4", main() is called, but after it returns, adminpanel() is called again unconditionally on line 205, causing unexpected re-entry.
  3. Using recursion for the menu loop can cause stack overflow with extended use.

Apply this diff to fix:

 def adminpanel():
-    users = load_users()  # Load users at the start
-
-    Rabbit.sleep(1)
-    print("\n=== Admin Panel ===")
-    print("1: Change a Users Username")
-    print("2: See all users")
-    print("3: Delete a User account")
-    print("4: Exit Admin Panel")
-
-    choice = input("\nEnter your choice (1-4): ").strip()
-
-    if choice == "1":
-        change_username()
-    elif choice == "2":
-        see_all_users()
-    elif choice == "3":
-        delete_user()
-    elif choice == "4":
-        print("Exiting admin panel...")
-        main()
-    else:
-        print("Invalid choice. Please try again.")
-
-    # Loop back to admin panel
-    adminpanel()
+    while True:
+        Rabbit.sleep(1)
+        print("\n=== Admin Panel ===")
+        print("1: Change a Users Username")
+        print("2: See all users")
+        print("3: Delete a User account")
+        print("4: Exit Admin Panel")
+
+        choice = input("\nEnter your choice (1-4): ").strip()
+
+        if choice == "1":
+            change_username()
+        elif choice == "2":
+            see_all_users()
+        elif choice == "3":
+            delete_user()
+        elif choice == "4":
+            print("Exiting admin panel...")
+            return  # Return to caller instead of calling main()
+        else:
+            print("Invalid choice. Please try again.")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def adminpanel():
users = load_users() # Load users at the start
Rabbit.sleep(1)
print("\n=== Admin Panel ===")
print("1: Change a Users Username")
print("2: See all users")
print("3: Delete a User account")
print("4: Exit Admin Panel")
choice = input("\nEnter your choice (1-4): ").strip()
if choice == "1":
change_username()
elif choice == "2":
see_all_users()
elif choice == "3":
delete_user()
elif choice == "4":
print("Exiting admin panel...")
main()
else:
print("Invalid choice. Please try again.")
# Loop back to admin panel
adminpanel()
def adminpanel():
while True:
Rabbit.sleep(1)
print("\n=== Admin Panel ===")
print("1: Change a Users Username")
print("2: See all users")
print("3: Delete a User account")
print("4: Exit Admin Panel")
choice = input("\nEnter your choice (1-4): ").strip()
if choice == "1":
change_username()
elif choice == "2":
see_all_users()
elif choice == "3":
delete_user()
elif choice == "4":
print("Exiting admin panel...")
return # Return to caller instead of calling main()
else:
print("Invalid choice. Please try again.")
🧰 Tools
🪛 Ruff (0.14.8)

181-181: Local variable users is assigned to but never used

Remove assignment to unused variable users

(F841)

🤖 Prompt for AI Agents
In Backend user system/lgoin system.py around lines 180 to 205, remove the
unused users = load_users() or use it where needed, replace the recursive
adminpanel() calls with an explicit while True loop for the menu, handle choices
inside the loop, and on choice "4" break/return so you do not call main() and
then re-enter the admin panel; ensure there is no unconditional recursive
adminpanel() at the end and avoid deep recursion to prevent stack overflow.

Comment on lines +224 to +228
new_username = input("Enter the new username: ").strip()

if new_username in users:
print(f"Username '{new_username}' already exists.")
return
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing username validation.

The new username isn't validated for length (max 12 characters) or empty strings, unlike signup() which enforces these constraints. This allows creating usernames that bypass signup rules.

     new_username = input("Enter the new username: ").strip()
 
+    if not new_username:
+        print("Username cannot be empty.")
+        return
+
+    if len(new_username) > 12:
+        print("Username too long (max 12 characters).")
+        return
+
     if new_username in users:
         print(f"Username '{new_username}' already exists.")
         return
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
new_username = input("Enter the new username: ").strip()
if new_username in users:
print(f"Username '{new_username}' already exists.")
return
new_username = input("Enter the new username: ").strip()
if not new_username:
print("Username cannot be empty.")
return
if len(new_username) > 12:
print("Username too long (max 12 characters).")
return
if new_username in users:
print(f"Username '{new_username}' already exists.")
return
🤖 Prompt for AI Agents
In Backend user system/lgoin system.py around lines 224 to 228, the new_username
input lacks the same validation as signup; add checks after stripping to ensure
the username is not empty and does not exceed 12 characters (e.g., if not
new_username or len(new_username) > 12: print an explanatory message and
return), and keep the existing duplicate check; mirror the exact validation
rules used by signup to prevent bypassing signup constraints.

Comment on lines 291 to +297
if adminlogin():
print("Admin access granted!")
global passwordattempts
passwordattempts = 0
adminpanel()
else:
print("Admin login failed.")
main()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Duplicate global declaration and recursive calls.

  1. Line 293 is a redundant global passwordattempts declaration (already declared at line 277) and placing it inside a nested block causes a SyntaxWarning.
  2. Line 297 uses recursion for retrying, which can cause stack overflow with repeated failures.

Consider using a loop-based approach for the main menu:

 def main():
-    global passwordattempts
-    print("1. Signup")
-    print("2. Login")
-    choice = input("Choose: ")
-
-    if choice == "1":
-        signup()
-    elif choice == "2":
-        if login():
-            print("Welcome! You are now logged in.")
-            # Continue with your program
-        else:
-            print("Login failed. Please try again.")
-    elif choice == login_secret:
-        if adminlogin():
-            print("Admin access granted!")
-            global passwordattempts
-            passwordattempts = 0
-            adminpanel()
-        else:
-            main()
-    else:
-        print("Invalid choice")
+    global passwordattempts
+    while True:
+        print("1. Signup")
+        print("2. Login")
+        choice = input("Choose: ")
+
+        if choice == "1":
+            signup()
+        elif choice == "2":
+            if login():
+                print("Welcome! You are now logged in.")
+                # Continue with your program
+                break
+            else:
+                print("Login failed. Please try again.")
+        elif choice == login_secret:
+            if adminlogin():
+                print("Admin access granted!")
+                passwordattempts = 0
+                adminpanel()
+            # Loop continues if adminlogin fails
+        else:
+            print("Invalid choice")

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In Backend user system/lgoin system.py around lines 291 to 297, remove the
redundant in-block "global passwordattempts" (it's already declared at line 277)
and avoid the recursive call to main() for retries; instead ensure the global is
declared once at the top of the function or module and refactor control flow to
use a loop-based retry mechanism (e.g., while/for loop) that resets
passwordattempts on successful adminlogin() and calls adminpanel() directly
without recursion, and on failure continues the loop or exits gracefully to
prevent stack growth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants