nutools/ulib/support/mkcrypt.py

31 lines
788 B
Python
Executable File

#!/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)
elif args[0] == '--':
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)