简体   繁体   中英

Python SHA512 salted passwords with crypt on MacOS X

I am trying to generate encrypted password strings, similar to /etc/shadow in Linux. For some reason the output I am getting is different. Any ideas what am I missing and is one has longer than the other (not counting the salt portion)?

#!/usr/bin/python
import crypt

alg = 6  # SHA512
salt = 'vb1tLY1qiY'
word = 'password'

insalt = '${}${}$'.format(alg, salt)

cryptWord = crypt.crypt(word, insalt)
print cryptWord

The output is: $6FMi11BJFsAc

If I generate this in Linux like this:

mkpasswd --method=sha-512 --salt=vb1tLY1qiY password

The output is: $6$vb1tLY1qiY$WFHTa6CRShEuKg63vuPTYOVRK1oQiM6johIEs2JslF1904VhEdSXlHje74eB4uLXHrKNyZ4bPjSlWpZD6qIo71

I was able to use passlib. It doesn't come installed as part of python (at least on OS X) but, you can install it via pip.

sudo easy_install pip
pip install passlib
python -c "from passlib.hash import sha512_crypt; import getpass,string,random; print sha512_crypt.using(salt=''.join([random.choice(string.ascii_letters + string.digits) for _ in range(16)]),rounds=5000).hash(getpass.getpass())"

https://gist.github.com/hbeatty/25db5847e7068335681db88248d0deaf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM