Question

I have this real simple encryption that I used for my site. I am trying to convert all my code from php to python, but I can't figure out how to get python to produce the same output that php did with this code.

function myhash($word){
  $salt = "$2a$06$" . substr(sha1($word) , 0, 22) . "$";
  return crypt($word, $salt);
}

Seeing as I already have quite a few passwords stored with this encryption, it would be silly to make a new encryption. What to do?

Was it helpful?

Solution

There is no blowfish built in. If you can use other modules try bcrypt it does exactly what you need. So the function will be:

import hashlib
import brypt
def myhash(word):
    salt = "$2a$06$" + hashlib.sha1(word).hexdigest()[0:22] + "$"
    return bcrypt.hashpw(word, salt)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top