Migrating passwords from web2py to Django -
In my password is stored in web2py using SHA 512 algorithm. Now I am migrating the model of the degegoon and Similarly, the hash password in the DNS is required by using SHA 512 in the same way as Web 2py so that I can authenticate the old users with the same password. Please suggest some kind of suggestion. According to this, a Python snippet will be used to revive the Convert used in web2py:
>
MD5 import from Hashilib Import HMAC hmac_key = '& lt; Your secret key & gt; ' Password = 'unsafe' thehash = hmac.new (hmac_key, password) .hxdigest () thehash print uses web2py hmac (which is plain text of your secret + user's password ) The last hash and just a straight MD5 / SHA hash (depending on your setting) Therefore you have to swap MD5 for SHA in the above example so that you can work at the end. But you need to implement this implementation in your new application, as long as they do not have the same secret key.
According to the hash, it gets stored in the following format:
So if a salt is used then it is stored with a hash, which makes it easy to hold salt for use in your new application. Dollar signs make it easy to parse every value.
Algo, salt, hash = password_hash.split ("$")UPDATE: I pulled the Web2py source to do the code you gave below Need to update that variable hmac_key with the value that you set for auth.settings.hmac_key. Hopefully, when you run (after updating the hmac_key variable), this hash must match.
hashlib Import SHA512 import h hashlib import HMAC = "SHA512 $ b850ed44943b861b print $ c90901439983bce7fd512592b20d83f8e654632dee51de515773e70eabe609f62cebec64fed4df03acd54e6a627c9291e70fdf3a89996ffa796897c159e95c11" algo, salt, hash = h.split ( "$") "crypted hash:% s"% Receive this value from auth.settings.hmac_key. Hmac_key = "" def get_digest (value): "" A hashibb digest algorithm returns from string "" if not "(e.g., str) : Return value value = value.lower () if value == "md5": return md5 elif value == "sha1": return sha1 elif value == "sha224": return sha224 elif value == "sha256": return sha256 Elif Value == "sha384": return sha384 elif value == "sha512" : Return sha512 and: Increase valueError ("Invalid digest algorithm:% s"% value) #hashed = simple_hash (self.password, key, salt, digest_alg) Def simple_hash (text, key = '', cell T = '', Digest_alg = 'md5'): "Generates a hash with given text using specified digest hashing algorithm" "If digest_Leg is not there: increase runtime error (" digest_ALG = simple with none ") elif not isinstance (digest_alg) ), Str): # Manual Approach H = Digest_ALG (Text + Key + Salt) Alif Diazes T_lag.startless ('PBKDF2'): #Newest and good! (Text, salt, int (key), int (keylen), get_digest (alg)) Alief key: # Use HMAC digest_alg = (PPDDF 2_Hx) is compatible with third-party systems h = get_digest (digest_alg) () h. Update (text + salt) returns h.hexdigest () print "h" (html) hash result:% s "% simple_hash (pwd, hmac_key, salt," sha512 ")
Comments
Post a Comment