-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHash_pass
29 lines (24 loc) · 859 Bytes
/
Hash_pass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import mariadb
import bcrypt
try:
conn = mariadb.connect(
user="root",
password="database",
host="127.0.0.1",
database="users"
)
cursor = conn.cursor()
except mariadb.Error as e:
print(f"Error connecting to MariaDB: {e}")
sys.exit(1)
cursor.execute("SELECT id, username, password FROM users")
users = cursor.fetchall()
for user in users:
user_id, username, plain_password = user
# Presupunând că plain_password este deja hash-uit, înlocuiește-l cu un nou hash
if not plain_password.startswith('$2b$'):
hashed_password = bcrypt.hashpw(plain_password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
cursor.execute("UPDATE users SET password=%s WHERE id=%s", (hashed_password, user_id))
print(f"Updated password for user: {username}")
conn.commit()
conn.close()