Initial commit
This commit is contained in:
41
migrate_passwords.py
Normal file
41
migrate_passwords.py
Normal file
@@ -0,0 +1,41 @@
|
||||
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())
|
||||
Reference in New Issue
Block a user