Remise en état des logs mysql

This commit is contained in:
2025-09-04 11:00:39 +02:00
parent 4de3f030c3
commit 403e82deec
14 changed files with 2373 additions and 12 deletions

39
scripts/hash_passwords.py Normal file
View File

@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
import mysql.connector
import bcrypt
from dotenv import load_dotenv
import os
# Charger les variables d'environnement depuis .env
load_dotenv()
conn = mysql.connector.connect(
host=os.getenv("DB_HOST"),
user=os.getenv("DB_USER"),
password=os.getenv("DB_PASSWORD"),
database=os.getenv("DB_NAME")
)
cursor = conn.cursor()
cursor.execute("SELECT utilisateur, mot_de_passe FROM MotsDePasse")
utilisateurs = cursor.fetchall()
def hash_password(plain_text_password):
return bcrypt.hashpw(plain_text_password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
for utilisateur, mot_de_passe in utilisateurs:
if mot_de_passe.startswith('$2b$') or mot_de_passe.startswith('$2a$'):
print(f"{utilisateur} : déjà haché")
continue
hashe = hash_password(mot_de_passe)
cursor.execute("UPDATE MotsDePasse SET mot_de_passe = %s WHERE utilisateur = %s", (hashe, utilisateur))
print(f"{utilisateur} : mot de passe haché")
conn.commit()
conn.close()
print("Mise à jour terminée.")