Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize account password hiding in python

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces you how to achieve account password hiding in python, the content is very detailed, interested friends can refer to, hope to be helpful to you.

We will learn how to hide passwords and user names in environment variables on Windows machines. Hard-coding usernames and passwords in code is a common mistake made by beginners in learning Python. Hiding this information in environment variables allows you to access your password information in the code without requiring anyone else to see the username and password from your source code. The following methods are hard-coded and are not recommended:

# many beginners will write something like this: db_user = 'sa'db_passwpord =' VGHYJHG user name and password directly leak the database user name and password in the source code print (db_user) print (db_passwpord)

Next, we add the user name and password information to the windows environment variable, and then call it by code. Right-click on the computer-Properties-Advanced system Settings-Environment variables, and select New to add information in the system variable as shown in the figure:

Next we use the os module to call the hidden username password:

Import osdb_user_hiding = os.environ.get ('DB_USER') db_passwpord_hiding = os.environ.get (' DB_PASSWORD') print (db_user_hiding) # adminprint (db_passwpord_hiding) # VGHYJHGG needs to close the current python file when calling: # if the print result is JHG, the current file needs to be closed # when reopening the file, run the code as above. On how to achieve account password hiding in python to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report