Created
September 12, 2016 05:43
-
-
Save kacchan822/8e6ab352daa59f074c1e1508d4457a79 to your computer and use it in GitHub Desktop.
Genarate MD5-CRYPT password string from PLAIN password string for python 2.x or higher.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gen_crypt_password(password): | |
from crypt import crypt | |
import random | |
""" MD5-CRYPTパスワード文字列を生成 for python2.x | |
"salt"は[a-zA-Z0-9./]から選ばえれることになっているので、 | |
chr()でアルファベット大文字(65~91)、小文字(97~123)のシーケンスを生成して、 | |
.と/を付け加えて、"salt"の元とする | |
""" | |
random.seed() | |
salt_seeds = \ | |
[chr(i) for i in range(65, 65+26)] + \ | |
[chr(i) for i in range(97, 97+26)] + \ | |
['/', '.'] | |
salt = ''.join(random.sample(salt_seeds, 8)) | |
crypt_password = crypt(password, '$1${0}$'.format(salt)) | |
return crypt_password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment