FastAPI bcrypt 비밀번호 암호화 - 45

2023. 1. 7. 17:30·Develop/FastAPI
728x90
SMALL
bcrypt 알고리즘을 사용해서 비밀번호를 암호화시켜 저장해 보자 

 

1. bcrypt 설치

=> 일반적으로 규정을 준수해야할 상황이 아니라면 구현이 쉽고 비교적 강력하다.

터미널에  pip install "passlib[bcrypt]" 다운

 

2. 라이브러리 import

from passlib.context import CryptContext

bcrypt_context = CryptContext(schemes=['bcrypt'], deprecated="auto")

 

3. 함수 생성 및 POST API 수정

def get_password_hash(password):
    return bcrypt_context.hash(password)
    
    
    
@app.post("/create/user")
async def create_new_user(create_user: CreateUser):
    create_user_model = models.Users()
    create_user_model.email = create_user.email
    create_user_model.username = create_user.username
    create_user_model.first_name = create_user.first_name
    create_user_model.last_name = create_user.last_name

    hash_password = get_password_hash(create_user.password)

    create_user_model.hashed_password = hash_password
    create_user_model.is_active = True

 

4. Swagger 확인

유저 데이터를 생성하면 패스워드가 암호화 된 것을 확인할 수 있다.

 

5. 암호화 사용 참고

  • ISO-27001 보안 규정을 준수해야하는 상황이면 PBKDF2
  • 보안 시스템을 구현하는데 많은 비용을 투자할 수 있다면, Scrpyt
728x90
SMALL
저작자표시 비영리 변경금지 (새창열림)

'Develop > FastAPI' 카테고리의 다른 글

FastAPI 사용자 인증 - 47  (0) 2023.01.07
FastAPI 데이터베이스에 유저 데이터 저장하기 - 46  (0) 2023.01.07
FastAPI Create Authentication & Post Request - 44  (0) 2023.01.07
FastAPI Create Users Table / Create Foreign Key - 43  (0) 2023.01.07
FastAPI Database Relationship / Foreign Key / Query- 42  (0) 2023.01.07
'Develop/FastAPI' 카테고리의 다른 글
  • FastAPI 사용자 인증 - 47
  • FastAPI 데이터베이스에 유저 데이터 저장하기 - 46
  • FastAPI Create Authentication & Post Request - 44
  • FastAPI Create Users Table / Create Foreign Key - 43
동석해요
동석해요
공부하고 싶은게 많은, 사소한 IT 지식들 공유
    250x250
  • 동석해요
    개발로 자기계발
    동석해요
  • 전체
    오늘
    어제
    • 분류 전체보기 (226)
      • Develop (126)
        • 기초지식 (12)
        • FastAPI (102)
        • Django (11)
      • Database & Data (62)
        • 기초지식 (16)
        • MySQL (29)
        • PostgreSQL (8)
        • 데이터 분석 (9)
      • 인공지능 (11)
        • PyTorch (9)
      • Cloud (8)
        • AWS (4)
        • GCP (2)
      • 버그처리 (14)
      • 회고 & 일상 (5)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.3
동석해요
FastAPI bcrypt 비밀번호 암호화 - 45
상단으로

티스토리툴바