SAuth/adduser.py

27 lines
699 B
Python
Raw Normal View History

2019-01-17 18:20:13 +00:00
#!/usr/bin/env python3
# -*-coding:utf-8 -*
import sauth
import getpass
import argparse
parser = argparse.ArgumentParser(description="""
Add a user with its password
""", formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('username', help="Username to add")
parser.add_argument('--password', '-p', help="Password. If not provided will be asked", type=str, dest='password')
args = parser.parse_args()
if args.password is None :
password = getpass.getpass('Password : ')
else:
password = args.password
sa = sauth.SAuth()
if sa.add_user(args.username, password):
print("User added !")
else:
print("An error occured (user already present for instance)")