문제

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