[Code] 암호화

Jongjin Na·2022년 10월 27일
1

CODE

목록 보기
1/5
post-thumbnail

암호화

그냥 TIL처럼 프로그래밍 공부하면서 배운거 간단하게 적을거야.

2022.10.27.

import bcrypt

ex_id = "member1"
ex_password = 'password1234'
bpass = bcrypt.hashpw(ex_password.encode('utf-8'), bcrypt.gensalt())

# 디비 구현 귀찮아서 딕셔너리로 만드는 디비 ;;
dic = {}
dic[ex_id] = bpass.decode('utf-8')

cid = input("plz input your id: ")
if cid in dic:
  while 1:
    cpass = input("plz input your password: ")
    answer = bcrypt.checkpw(cpass.encode('utf-8'), dic[cid].encode('utf-8'))
    if answer:
      print("log in")
      break
    else:
      print("plz re input")
else:
  print("there is no id")

Q.
DB에 넣을 때 decode 해서 넣어야 된다고 하는데, 왜 그런가. byte로 들어가면 안되나..?
로그인 한 다음에 JWT로 토큰을 발행한다는데 왜?? 로그인 하면 인증이 끝난거 아닌가

2022.00.00.

ref

2021 백엔드 개발자 로드맵 中 웹 보안 지식

안전한 패스워드 보안(패스워드 암호화 저장법 /bcrypt, scrypt, pdkdf2 )

replit

profile
안녕하세요. 나종진입니다.

0개의 댓글