A simple example just verifying and creating Django compatible passwords:
const hashers = ;const h = ;h; // prints the hashed password
You can also get a hashed password, identify the hashing algorithm, and verify the password. The below example is for Argon2PasswordHasher, a similar approach to the above code sample can be used for all the other algorithms.
const hashers = ;// Hashed password from Djangoconst hash_password = "argon2$argon2i$v=19$m=512,t=2,p=2$ZGIzQXZXdjlaMjRK$2ecZ6JAld41sKwh9Q8KEyQ";const hash_name = hashers;const hash_algorithm = hashers;hash_algorithm; // prints truehash_algorithm; // prints false
A good practice is to verify if the password is using the default algorithm, and update the password if necessary on the database. Every hashing algorithm has an algorithm name. You can pass it in and check if updates are required:
const hashers = ;const hash_password = "286755fad04869ca523320acce0dc6a4"; // "password" in md5const mustUpdate = hashers;// mustUpdate is true since we do not want MD5 hash passwords, pbkdf2_sha256 is the defaultconst hash_algorithm = hashers;// update the users password in the database by re encoding the password here
npm install node-django-hashers