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.")
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? ")
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()
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()
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))
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))
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))
def get_password(self, prompt="Password: "): return tty.getpass(prompt)
def ask_password(): password = tty.getpass("Password? ") password2 = tty.getpass("Again: ") if password != password2: return None return password