python - getpass non-clear text passwords

In carrying out our input ( 'Please enter your password:') when displayed in plain text, and getpass to solve the problem in plain text:

1 we execute the INPUT ( ' Please enter your password: ' ) when displayed in plain text, and getpass to solve the problem in plain text:
 2  
3  Import getpass
 4  Import smtplib
 5  from email.mime.text Import MimeText
 6  
7  class Sendmain (Object):
 . 8      DEF  the __init__ (Self, FROMUSER, pwd, TOUSER, title, Content, Host = ' smtp.sina.cn ' , Port = 25 ):
 . 9          self.touser = TOUSER
 10          self.content = Content
 . 11          Self = .title title
12         self.host=host
13         self.port=port
14         self.fromuser=fromuser
15         self.pwd=pwd
16 
17     def send_main(self):
18         msg=MIMEText(self.content,'plain','utf-8')
19         msg["Subject"]=self.title
20         msg['From']=self.fromuser
21         msg['To']=self.touser
22 
23         try:
24             smtp=smtplib.SMTP(self.host,self.port)
25             smtp.login(self.fromuser,self.pwd)
26             smtp.sendmail(self.fromuser,self.touser,msg.as_string())
27             smtp.quit()
28             print('邮件发送成功')
29 
30         except smtplib.SMTPException as e:
31             print(e)
32 
33 if __name__ == '__main__':
34     INPUT = FROMUSER ( ' Enter the sender account: ' )
 35      pwd = getpass.getpass ( " Enter your password: " )
 36      TOUSER = ' [email protected] ' 
37 [      title = ' password practice ' 
38 is      Content = ' the getpass exercise ' 
39      Send = Sendmain (FROMUSER, pwd, TOUSER, title, Content)
 40      send.send_main ()

 

FIG execution results into:

 

Note that: only be in the terminal at the time of execution, otherwise invalid getpass

Guess you like

Origin www.cnblogs.com/xiao-erge112700/p/11497682.html