"""
顯示臨時密碼
"""
import psycopg2

conn = psycopg2.connect(
    host="10.1.0.20",
    port=5433,
    database="hr_portal",
    user="admin",
    password="DC1qaz2wsx"
)
cur = conn.cursor()

# 查詢最新的臨時密碼
cur.execute("""
    SELECT id, username, plain_password, password_hash, created_at, is_used
    FROM temporary_passwords
    ORDER BY created_at DESC
    LIMIT 5;
""")

passwords = cur.fetchall()

print("=== Temporary Passwords ===\n")

if passwords:
    for pw in passwords:
        print(f"ID: {pw[0]}")
        print(f"Username: {pw[1]}")
        print(f"Plain Password: {pw[2] if pw[2] else '(已清除)'}")
        print(f"Password Hash: {pw[3][:50]}..." if pw[3] else "None")
        print(f"Created At: {pw[4]}")
        print(f"Is Used: {pw[5]}")
        print("-" * 50)
else:
    print("No temporary passwords found")

cur.close()
conn.close()
