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?

有帮助吗?

解决方案

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)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top