Skip to content

Python 生成 /etc/shadow 的密码

Published: at 00:00
说明
*	SHA512加密
*	OSX下生成的密码不对
代码
#coding=utf-8
"""

Usage: topwd.py """ author = ‘nate’

import random
import crypt
from docopt import docopt

if __name__ == '__main__':
	args = docopt(__doc__)
	password = args['<password>']
	salt_set = ('abcdefghijklmnopqrstuvwxyz'
            	'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
            	'0123456789./')
	print crypt.crypt(password, '$6${salt}'.format(salt=''.join([random.choice(salt_set) for i in range(8)])))