Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify passwords created by Django(make_password) without Django

Tags:

python

django

I have used Django and handled password with make_password and check_password.

however, I get to change a framework to fastapi.

With fastapi, I need to verify passwords that are created by Django because I should use the same database with the data.

How can I handle the passwords in the way that is compatible with Django?

Password's format stored in database is like that 'pbkdf2_sha256$100000$Dl6Atsc1xX0A$0QFvZLpKdcvcmCNixVCdEA5gJ67yef/gkgaCKTYzoo4='

like image 948
SangminKim Avatar asked Dec 04 '25 03:12

SangminKim


1 Answers

I have found passlib support Django compatible way.

from django.contrib.auth.hashers import make_password
from passlib.handlers.django import django_pbkdf2_sha256

password = 'testpassword123'
django_hash = make_password(password)   
is_verified = django_pbkdf2_sha256.verify(password, django_hash)

if is_verified:
  print('Correct!!')
like image 186
SangminKim Avatar answered Dec 05 '25 18:12

SangminKim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!