Some checks failed
Tests / Backend Tests (Python) (3.10) (push) Has been cancelled
Tests / Backend Tests (Python) (3.11) (push) Has been cancelled
Tests / Backend Tests (Python) (3.12) (push) Has been cancelled
Tests / Frontend Tests (JS) (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / All Tests Passed (push) Has been cancelled
30 lines
1005 B
Python
30 lines
1005 B
Python
import asyncio
|
|
import sys
|
|
import os
|
|
|
|
# Ajouter le répertoire courant au PYTHONPATH pour trouver le module 'app'
|
|
sys.path.insert(0, os.path.abspath(os.getcwd()))
|
|
|
|
from app.models.database import async_session_maker
|
|
from app.crud.user import UserRepository
|
|
from app.services.auth_service import hash_password
|
|
|
|
async def reset_password(username, new_password):
|
|
async with async_session_maker() as session:
|
|
repo = UserRepository(session)
|
|
user = await repo.get_by_username(username)
|
|
|
|
if not user:
|
|
print(f"❌ Utilisateur '{username}' non trouvé.")
|
|
return
|
|
|
|
user.hashed_password = hash_password(new_password)
|
|
await session.commit()
|
|
print(f"✅ Mot de passe réinitialisé avec succès pour : {username}")
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) < 3:
|
|
print("Usage: python reset_password.py <username> <nouveau_mot_de_passe>")
|
|
else:
|
|
asyncio.run(reset_password(sys.argv[1], sys.argv[2]))
|