nutools/lib/ulib/support/mkcrypt.py

31 lines
806 B
Python
Raw Normal View History

2013-08-27 15:14:44 +04:00
#!/usr/bin/env python
# -*- coding: utf-8 mode: python -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
import sys
import random
try: from crypt import crypt
except ImportError: sys.exit(1)
CHARS = "./abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
if __name__ == '__main__':
args = sys.argv[1:]
if len(args) == 1 and args[0] == '--help':
print """mkcrypt.py - crypter un mot de passe avec la méthode crypt
USAGE
mkcrypt.py clear [salt]"""
sys.exit(0)
2014-02-25 08:58:04 +04:00
elif len(args) > 0 and args[0] == '--':
2013-08-27 15:14:44 +04:00
args = args[1:]
clpasswd = args[0:1] and args[0] or None
salt = args[1:2] and args[1] or random.choice(CHARS) + random.choice(CHARS)
if clpasswd is not None:
print crypt(clpasswd, salt)
sys.exit(0)
else:
sys.exit(1)