示例#1
0
文件: cli.py 项目: tijmengit/pycopia
 def passwd(self, argv):
     """passwd [-a <authservice> | -l | -s ] <username>
 Change the password for the given user. Also change the authorization method."""
     opts, longopts, args = self.getopt(argv, "a:sl")
     for opt, arg in opts:
         if opt == "-a":
             longopts["authservice"] = arg
         elif opt == "-l":
             longopts["authservice"] = "local"
         elif opt == "-s":
             longopts["authservice"] = "system"
     username = args[0]
     user = _session.query(models.User).filter(models.User.username==username).one()
     tries = 0
     while tries < 3:
         newpass = tty.getpass("New password for %s: " % (user,))
         newpass2 = tty.getpass("New password again: ")
         if newpass == newpass2:
             break
         tries += 1
     else:
         self._print("Password not updated.")
         return
     if newpass:
         user.password = newpass
         models.update(user, **longopts)
         _session.commit()
     else:
         self._print("No password, not updated.")
示例#2
0
def get_pass(verify):
    """Basic callback for getting passphrase."""
    if verify:
        retries = 3
        while retries > 0:
            pw = tty.getpass("Passphrase? ")
            npw = tty.getpass("Passphrase again? ")
            if pw == npw:
                return pw
            print("Phrases don't match. Please try again.")
            retries -= 1
        raise crypto.Error("Too many tries reading passphrase.")
    else:
        return tty.getpass("Passphrase? ")
示例#3
0
def get_pass(verify):
    """Basic callback for getting passphrase."""
    if verify:
        retries = 3
        while retries > 0:
            pw = tty.getpass("Passphrase? ")
            npw = tty.getpass("Passphrase again? ")
            if pw == npw:
                return pw
            print("Phrases don't match. Please try again.")
            retries -= 1
        raise crypto.Error("Too many tries reading passphrase.")
    else:
        return tty.getpass("Passphrase? ")
示例#4
0
def submit(crontab, username=None, password=None):
    """Submit a crontab via the crontab program.
    Supply a crontab object. If it is to be installed for a different user
    supply the `username` parameter. If this is not run as root, then sudo is
    used and you must supply your own password for sudo."""
    if username is None:
        ct = proctools.spawnpipe("crontab -")
        ct.write(str(crontab))
        ct.close()
        return ct.wait()
    else:
        if os.getuid() == 0:
            ct = proctools.spawnpipe("crontab -u %s -" % (username, ))
            ct.write(str(crontab))
            ct.close()
            return ct.wait()
        else:
            from pycopia import sudo
            if password is None:
                from pycopia import tty
                password = tty.getpass("Your password:"******"crontab -u %s -" % (username, ), password=password)
            ct.write(str(crontab))
            ct.close()
            return ct.wait()
示例#5
0
def submit(crontab, username=None, password=None):
    """Submit a crontab via the crontab program. 
    Supply a crontab object. If it is to be installed for a different user
    supply the `username` parameter. If this is not run as root, then sudo is
    used and you must supply your own password for sudo."""
    if username is None:
        ct = proctools.spawnpipe("crontab -")
        ct.write(str(crontab))
        ct.close()
        return ct.wait()
    else:
        if os.getuid() == 0:
            ct = proctools.spawnpipe("crontab -u %s -" % (username,))
            ct.write(str(crontab))
            ct.close()
            return ct.wait()
        else:
            from pycopia import sudo
            if password is None:
                from pycopia import tty
                password = tty.getpass("Your password:"******"crontab -u %s -" % (username,), password=password)
            ct.write(str(crontab))
            ct.close()
            return ct.wait()
示例#6
0
文件: imapCLI.py 项目: kdart/pycopia3
 def login_cram_md5(self, argv):
     """login_cram_md5 [<user>]
 Force logging in using CRAM_MD5."""
     if len(argv) > 1:
         USER = argv[1]
     else:
         USER = tty.getuser()
     PASS = tty.getpass()
     self._print_msg(self._client.login_cram_md5(USER, PASS))
示例#7
0
文件: imapCLI.py 项目: kdart/pycopia3
 def login(self, argv):
     """login [<username>]
 Identify client using plaintext password."""
     if len(argv) > 1:
         USER = argv[1]
     else:
         USER = tty.getuser()
     PASS = tty.getpass()
     self._print_msg(self._client.login(USER, PASS))
示例#8
0
 def login_cram_md5(self, argv):
     """login_cram_md5 [<user>]
 Force logging in using CRAM_MD5."""
     if len(argv) > 1:
         USER = argv[1]
     else:
         USER = tty.getuser()
     PASS = tty.getpass()
     self._print_msg(self._client.login_cram_md5(USER, PASS))
示例#9
0
 def login(self, argv):
     """login [<username>]
 Identify client using plaintext password."""
     if len(argv) > 1:
         USER = argv[1]
     else:
         USER = tty.getuser()
     PASS = tty.getpass()
     self._print_msg(self._client.login(USER, PASS))
示例#10
0
 def login(self, argv):
     """login <user> [<password>]
 Perform an authentication protocol with the given name and password.
 Perform this after `ehlo`."""
     user = argv[1]
     if len(argv) > 2:
         passwd = argv[2]
     else:
         passwd = tty.getpass("AUTH password: ")
     self._print_msg(self._client.login(user, passwd))
示例#11
0
 def login(self, argv):
     """login <user> [<password>]
 Perform an authentication protocol with the given name and password.
 Perform this after `ehlo`."""
     user = argv[1]
     if len(argv) > 2:
         passwd = argv[2]
     else:
         passwd = tty.getpass("AUTH password: ")
     self._print_msg(self._client.login(user, passwd))
示例#12
0
文件: UI.py 项目: kdart/pycopia3
 def get_password(self, prompt="Password: "):
     return tty.getpass(prompt)
示例#13
0
文件: users.py 项目: kdart/routerapp
def ask_password():
    password = tty.getpass("Password? ")
    password2 = tty.getpass("Again: ")
    if password != password2:
        return None
    return password
示例#14
0
 def get_password(self, prompt="Password: "):
     return tty.getpass(prompt)