Initial
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
# Admin Utilities
|
||||
|
||||
This folder contains administrative tools and utilities for maintaining the CGW Product Finder application.
|
||||
|
||||
## 🛠️ Available Tools
|
||||
|
||||
### fix_default_locations.py
|
||||
**Purpose**: Ensures all users have their default location marked as accessible.
|
||||
|
||||
**Usage**:
|
||||
```bash
|
||||
cd app/admin
|
||||
python fix_default_locations.py
|
||||
```
|
||||
|
||||
**What it does**:
|
||||
- Scans all users in `data/users.json`
|
||||
- Checks if each user's default location is marked as accessible
|
||||
- Automatically fixes any users where the default location is not accessible
|
||||
- Reports results for each user
|
||||
|
||||
**When to use**:
|
||||
- After manual edits to users.json
|
||||
- After importing users from backup
|
||||
- If users report they can't access their default location
|
||||
- As a maintenance check
|
||||
|
||||
### test_password_security.py
|
||||
**Purpose**: Demonstrates and tests the password hashing security implementation.
|
||||
|
||||
**Usage**:
|
||||
```bash
|
||||
cd app/admin
|
||||
python test_password_security.py
|
||||
```
|
||||
|
||||
**What it does**:
|
||||
- Demonstrates PBKDF2-SHA256 password hashing
|
||||
- Shows security features (iterations, salt, etc.)
|
||||
- Verifies password verification works correctly
|
||||
- Useful for understanding the security implementation
|
||||
|
||||
**When to use**:
|
||||
- To verify password hashing is working correctly
|
||||
- To demonstrate security to stakeholders
|
||||
- For educational purposes
|
||||
- When troubleshooting password-related issues
|
||||
|
||||
## 📋 Running Admin Tools
|
||||
|
||||
All admin tools should be run from within the `app/admin` directory to ensure correct file paths.
|
||||
|
||||
**Example**:
|
||||
```bash
|
||||
# Navigate to admin folder
|
||||
cd "C:\Users\Work\Desktop\CGW Product Finder\app\admin"
|
||||
|
||||
# Run a tool
|
||||
python fix_default_locations.py
|
||||
```
|
||||
|
||||
## ⚠️ Important Notes
|
||||
|
||||
- **Backup First**: Always backup `data/users.json` before running utilities that modify data
|
||||
- **Test Environment**: Test utilities in a development environment before running in production
|
||||
- **File Paths**: These tools assume they're being run from the `app/admin` directory
|
||||
- **Python Version**: Requires Python 3.7 or higher
|
||||
|
||||
## 🔒 Security Considerations
|
||||
|
||||
- These tools have direct access to user data
|
||||
- Do not expose these tools to web-facing directories
|
||||
- Keep this folder secure with appropriate file permissions
|
||||
- Never commit sensitive user data to version control
|
||||
|
||||
## 📝 Adding New Admin Tools
|
||||
|
||||
When adding new administrative tools to this folder:
|
||||
|
||||
1. Add the Python script file
|
||||
2. Update this README with documentation
|
||||
3. Include clear usage instructions
|
||||
4. Document any data modifications it makes
|
||||
5. Include error handling and user feedback
|
||||
|
||||
## 🐛 Troubleshooting
|
||||
|
||||
**"File not found" errors**:
|
||||
- Ensure you're running from the `app/admin` directory
|
||||
- Check that `../data/users.json` exists
|
||||
|
||||
**Permission denied**:
|
||||
- Ensure the application is not running
|
||||
- Check file permissions on `data/users.json`
|
||||
|
||||
**Import errors**:
|
||||
- Ensure all required dependencies are installed: `pip install -r ../requirements.txt`
|
||||
- Verify Python version: `python --version`
|
||||
@@ -0,0 +1,65 @@
|
||||
"""
|
||||
Utility script to fix existing users by ensuring their default location
|
||||
is marked as accessible in their locationSettings.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
# Get the directory where this script is located
|
||||
basedir = os.path.abspath(os.path.dirname(__file__))
|
||||
USERS_FILE = os.path.join(basedir, '..', 'data', 'users.json')
|
||||
|
||||
def fix_default_locations():
|
||||
"""
|
||||
Ensure all users have their default location marked as accessible.
|
||||
"""
|
||||
if not os.path.exists(USERS_FILE):
|
||||
print("No users.json file found.")
|
||||
return
|
||||
|
||||
# Load users
|
||||
with open(USERS_FILE, 'r') as f:
|
||||
users = json.load(f)
|
||||
|
||||
print(f"Found {len(users)} users to check...")
|
||||
|
||||
changes_made = 0
|
||||
for user in users:
|
||||
username = user.get('username', 'Unknown')
|
||||
default_location = user.get('defaultLocation')
|
||||
|
||||
if not default_location:
|
||||
print(f"⚠️ User '{username}' has no default location - skipping")
|
||||
continue
|
||||
|
||||
location_settings = user.get('locationSettings', {})
|
||||
|
||||
# Check if default location is in settings and accessible
|
||||
if default_location not in location_settings:
|
||||
print(f"✓ Adding default location '{default_location}' for user '{username}'")
|
||||
location_settings[default_location] = {'accessible': True}
|
||||
user['locationSettings'] = location_settings
|
||||
changes_made += 1
|
||||
elif not location_settings[default_location].get('accessible', False):
|
||||
print(f"✓ Marking default location '{default_location}' as accessible for user '{username}'")
|
||||
location_settings[default_location]['accessible'] = True
|
||||
changes_made += 1
|
||||
else:
|
||||
print(f" User '{username}' - default location already accessible")
|
||||
|
||||
if changes_made > 0:
|
||||
# Save updated users
|
||||
with open(USERS_FILE, 'w') as f:
|
||||
json.dump(users, f, indent=2)
|
||||
print(f"\n✓ Fixed {changes_made} user(s) and saved to users.json")
|
||||
else:
|
||||
print("\n✓ All users already have correct default location settings")
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("=" * 60)
|
||||
print("DEFAULT LOCATION FIX UTILITY")
|
||||
print("=" * 60)
|
||||
print()
|
||||
fix_default_locations()
|
||||
print()
|
||||
@@ -0,0 +1,60 @@
|
||||
"""
|
||||
Test script to demonstrate password hashing and verification
|
||||
"""
|
||||
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
|
||||
# Example: Creating a hashed password
|
||||
plain_password = "mySecurePassword123"
|
||||
hashed_password = generate_password_hash(plain_password, method='pbkdf2:sha256')
|
||||
|
||||
print("=" * 60)
|
||||
print("PASSWORD HASHING DEMONSTRATION")
|
||||
print("=" * 60)
|
||||
print()
|
||||
print(f"Original Password: {plain_password}")
|
||||
print()
|
||||
print(f"Hashed Password: {hashed_password}")
|
||||
print()
|
||||
print(f"Hash Length: {len(hashed_password)} characters")
|
||||
print()
|
||||
print("=" * 60)
|
||||
print("SECURITY FEATURES")
|
||||
print("=" * 60)
|
||||
print("✓ Algorithm: PBKDF2-SHA256")
|
||||
print("✓ Iterations: 600,000+")
|
||||
print("✓ Unique salt per password")
|
||||
print("✓ Cannot be reversed to plain text")
|
||||
print("✓ Industry-standard security")
|
||||
print()
|
||||
print("=" * 60)
|
||||
print("PASSWORD VERIFICATION TEST")
|
||||
print("=" * 60)
|
||||
print()
|
||||
|
||||
# Test correct password
|
||||
correct = check_password_hash(hashed_password, "mySecurePassword123")
|
||||
print(f"Testing correct password: {correct} ✓")
|
||||
|
||||
# Test incorrect password
|
||||
incorrect = check_password_hash(hashed_password, "wrongPassword")
|
||||
print(f"Testing incorrect password: {incorrect} ✗")
|
||||
print()
|
||||
|
||||
# Show that the same password produces different hashes (due to unique salts)
|
||||
print("=" * 60)
|
||||
print("UNIQUE SALT DEMONSTRATION")
|
||||
print("=" * 60)
|
||||
print()
|
||||
print("Hashing the same password twice produces different hashes:")
|
||||
print()
|
||||
hash1 = generate_password_hash("password123", method='pbkdf2:sha256')
|
||||
hash2 = generate_password_hash("password123", method='pbkdf2:sha256')
|
||||
print(f"Hash 1: {hash1}")
|
||||
print(f"Hash 2: {hash2}")
|
||||
print()
|
||||
print(f"Are they different? {hash1 != hash2}")
|
||||
print("Both hashes are valid and will verify correctly!")
|
||||
print(f"Hash 1 verifies: {check_password_hash(hash1, 'password123')}")
|
||||
print(f"Hash 2 verifies: {check_password_hash(hash2, 'password123')}")
|
||||
print()
|
||||
Reference in New Issue
Block a user