Created
February 19, 2019 17:29
-
-
Save romelgomez/1044182dc168d5a0c4107b088a077912 to your computer and use it in GitHub Desktop.
Import user of django to firebase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import base64 | |
from passlib.hash import pbkdf2_sha256, django_pbkdf2_sha256 | |
from passlib.utils import to_bytes, to_native_str | |
""" | |
The django password property has the hash in base64, and the salt not, so, the salt must have to be pass to base64 format to make it work. | |
auth:import y auth:export docs: https://firebase.google.com/docs/cli/auth?hl=es-419 | |
$ firebase auth:import sandbox/account_file.csv --hash-algo=PBKDF2_SHA256 --rounds=20000 --project <project_name> | |
The exmaple django 1.8 password is: pbkdf2_sha256$20000$VVEU1GnGCr0M$7ZtXwcAIAZXICBYXb82FVeCJAjdfWrBZ11gVzb2UGVc= | |
The salt source string is VVEU1GnGCr0M | |
The salt in base64 is VlZFVTFHbkdDcjBN | |
account_file.csv | |
555000444,[email protected],false,7ZtXwcAIAZXICBYXb82FVeCJAjdfWrBZ11gVzb2UGVc=,VlZFVTFHbkdDcjBN,,,,,,,,,,,,,,,,,,,,,, | |
[django_pbkdf2_sha256] != [pbkdf2_sha256_hash] they they differ slightly: | |
django_pbkdf2_sha256 >>> pbkdf2_sha256$20000$VVEU1GnGCr0M$7ZtXwcAIAZXICBYXb82FVeCJAjdfWrBZ11gVzb2UGVc= | |
pbkdf2_sha256_hash >>> $pbkdf2-sha256$20000$Z29vZ2xl$PtFLyZHJJucUa2KBg1iJeVJsivis8JimRhFifRRKlFc | |
django_pbkdf2_sha256 >>> ... _ | |
pbkdf2_sha256_hash >>> $ ... - | |
""" | |
# Hash generate by django 1.8 | |
django_1_8_password = "pbkdf2_sha256$20000$VVEU1GnGCr0M$7ZtXwcAIAZXICBYXb82FVeCJAjdfWrBZ11gVzb2UGVc=" | |
def getBase64 (s): | |
""" | |
s: string | |
""" | |
return base64.b64encode(to_bytes(s)) | |
def getHASH (salt, rounds, password): | |
""" | |
salt: string ~ is internally parse by to_bytes function | |
rounds: number | |
password: string | |
django 1.8 has 20000 ROUNDS or Iterations | |
django 1.11 has 36000 ROUNDS or Iterations | |
""" | |
return pbkdf2_sha256.using(salt=to_bytes(salt),rounds=rounds).hash(password) | |
pbkdf2_sha256_hash = getHASH('google', 20000, 'aA123456*') | |
assert pbkdf2_sha256.identify(pbkdf2_sha256_hash), "pbkdf2_sha256_hash is not valid pbkdf2_sha256 algorithm." | |
assert pbkdf2_sha256.verify('aA123456*', pbkdf2_sha256_hash), "pbkdf2_sha256_hash (pbkdf2_sha256 ~ algorithm) with the PASSWORD: aA123456*, is not valid." | |
# Is a negation >>> The hash is not valid pbkdf2_sha256 algorithm | |
assert not pbkdf2_sha256.identify(django_1_8_password), "is valid [pbkdf2_sha256] algorithm." | |
assert django_pbkdf2_sha256.identify(django_1_8_password), "is not valid [django_pbkdf2_sha256] algorithm." | |
print('pbkdf2_sha256_hash >>> ', pbkdf2_sha256_hash) | |
salt_in_B64 = getBase64('VVEU1GnGCr0M') | |
print('Salt in B64 >>>', salt_in_B64) # VlZFVTFHbkdDcjBN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment