Remise en état des logs mysql
This commit is contained in:
39
scripts/hash_passwords.py
Normal file
39
scripts/hash_passwords.py
Normal 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.")
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user