python 实现linux密码加密

python -c 'import crypt; print crypt.crypt("test", "$6$random_salt")'

6 is the type of hash for SHA-512

/etc/passwd 密码前二位代表加密方式
$1 -> MD5
$2 -> Blowfish (not in mainline glibc; added in some Linux distributions)
$5 -> SHA-256 (since glibc 2.7)
$6 -> SHA-512 (since glibc 2.7)

第二个$ 到第三个$之间为 随机的random password salt
python 生成8位随机random
salt=''.join(random.choice(string.ascii_letters + string.digits) for _ in range(8))


 

你可能感兴趣的:(python)