Files
iDRAC_Info/migrate_passwords.py
2025-10-05 17:37:51 +09:00

41 lines
1.0 KiB
Python

from __future__ import annotations
import sys
from pathlib import Path
from werkzeug.security import generate_password_hash
from flask import Flask
# 앱/DB/모델 임포트
from config import Config
from backend.models.user import db, User
BASE_DIR = Path(__file__).resolve().parent
def is_hashed(password: str) -> bool:
return password.startswith("pbkdf2:sha256")
def main() -> int:
# 별도 Flask 앱 컨텍스트 구성
app = Flask(__name__)
app.config.from_object(Config)
db.init_app(app)
with app.app_context():
users = User.query.all()
updated_count = 0
for user in users:
if user.password and not is_hashed(user.password):
print(f"🔄 변환 대상: {user.username}")
user.password = generate_password_hash(user.password)
updated_count += 1
if updated_count:
db.session.commit()
print(f"✅ 완료: {updated_count}명 해시 처리")
return 0
if __name__ == "__main__":
raise SystemExit(main())