mrdj204
mrdj204

Reputation: 73

Converting an blowfish encryption algo from php to python

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?

Upvotes: 2

Views: 674

Answers (1)

Denis.I
Denis.I

Reputation: 36

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)

Upvotes: 2

Related Questions