Files
vconnect-api/app/utils/security.py
unknown 513ff991eb
Some checks failed
Deploy VConnect API / Test Build (push) Successful in 23s
Deploy VConnect API / Deploy to Server (push) Failing after 9s
Update 2025-12-14 13:17:54
2025-12-14 13:17:54 +09:00

27 lines
887 B
Python

import bcrypt
# bcrypt 컨텍스트 제거 (직접 사용)
def hash_password(password: str) -> str:
"""비밀번호 해시화"""
# bcrypt는 bytes를 처리하므로 인코딩 필요
pwd_bytes = password.encode('utf-8')
salt = bcrypt.gensalt()
hashed = bcrypt.hashpw(pwd_bytes, salt)
return hashed.decode('utf-8')
def verify_password(plain_password: str, hashed_password: str) -> bool:
"""비밀번호 검증"""
try:
if not plain_password or not hashed_password:
return False
pwd_bytes = plain_password.encode('utf-8')
# DB에 저장된 해시는 str일 수 있으므로 인코딩
hashed_bytes = hashed_password.encode('utf-8')
return bcrypt.checkpw(pwd_bytes, hashed_bytes)
except Exception:
# 형식 오류 등 발생 시 인증 실패 처리
return False