57 lines
1.6 KiB
Python
Executable File
57 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Password Generator for Drakkenheim RAG Application
|
|
|
|
This script helps you generate secure password hashes and salts for authentication.
|
|
"""
|
|
|
|
import hashlib
|
|
import secrets
|
|
import sys
|
|
import getpass
|
|
|
|
def generate_salt(length=32):
|
|
"""Generate a random salt."""
|
|
return secrets.token_hex(length)
|
|
|
|
def hash_password(password, salt):
|
|
"""Hash a password with salt using SHA-256."""
|
|
return hashlib.sha256((password + salt).encode()).hexdigest()
|
|
|
|
def main():
|
|
print("🔐 Drakkenheim RAG - Password Generator")
|
|
print("=" * 40)
|
|
|
|
# Get password from user
|
|
password = getpass.getpass("Enter password: ")
|
|
if not password:
|
|
print("❌ Password cannot be empty!")
|
|
sys.exit(1)
|
|
|
|
# Confirm password
|
|
confirm_password = getpass.getpass("Confirm password: ")
|
|
if password != confirm_password:
|
|
print("❌ Passwords don't match!")
|
|
sys.exit(1)
|
|
|
|
# Generate salt and hash
|
|
salt = generate_salt()
|
|
password_hash = hash_password(password, salt)
|
|
|
|
print("\n✅ Password configuration generated!")
|
|
print("\n📋 Add these to your .env file:")
|
|
print("-" * 40)
|
|
print(f"APP_PASSWORD_HASH={password_hash}")
|
|
print(f"PASSWORD_SALT={salt}")
|
|
print("SESSION_TIMEOUT=3600")
|
|
print("-" * 40)
|
|
|
|
print("\n🔒 Security notes:")
|
|
print("• Keep your .env file secure and never commit it to version control")
|
|
print("• The salt should be unique for each deployment")
|
|
print("• SESSION_TIMEOUT is in seconds (3600 = 1 hour)")
|
|
print("• Users will be logged out automatically after the timeout")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|