Team1-TU-tech / login

0 stars 1 forks source link

Error: Invalid base64-encoded string: number of data characters (57) cannot be 1 more than a multiple of 4 #29

Open hamsunwoo opened 1 month ago

hamsunwoo commented 1 month ago

에러메세지

File "/Users/seon-u/final/login/.venv/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling
    result = func()
             ^^^^^^
File "/Users/seon-u/final/login/.venv/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec
    exec(code, module.__dict__)
File "/Users/seon-u/final/login/src/login/login.py", line 121, in <module>
    login_screen()
File "/Users/seon-u/final/login/src/login/login.py", line 86, in login_screen
    login(userid, password)
File "/Users/seon-u/final/login/src/login/login.py", line 63, in login
    if user['id'] == id and check_password(password, user['passwd']):
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/seon-u/final/login/src/login/login.py", line 54, in check_password
    decoded_hashed = base64.b64decode(hashed)
                     ^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/seon-u/.pyenv/versions/3.11.9/lib/python3.11/base64.py", line 88, in b64decode
    return binascii.a2b_base64(s, strict_mode=validate)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

코드

def check_password(passwd, hashed):
    decoded_hashed = base64.b64decode(hashed)
    return bcrypt.checkpw(passwd.encode(), decoded_hashed)
hamsunwoo commented 1 month ago

수정 후 코드

# 비밀번호 검증 함수
def check_password(passwd, hashed):
    return bcrypt.checkpw(passwd.encode(), hashed.encode())

Base64 인코딩이 필요 없이 해시를 문자열로 처리하고, 검증할 때도 문자열 그대로 bcrypt.checkpw를 사용하니 오류 해결