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 record user login log by python

2025-05-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "how to record user login log in python". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to record user login logs by python".

Task 1. Log the user login log import timedef show_info (): print ('enter the prompt number and perform the corresponding action: 0 exit) 1 View login log') # record log def write_logininfo (username): with open ('log.txt','a') as file: username {username}, login time: {time.strftime ("% Y-%m-%d% log") Time.localtime (time.time ())} 'file.write (s) file.write ('\ n') # read log def read_logininfo (): with open ('log.txt','r') as file: while True: line=file.readline () if line=='': break else: print (line End='\ t') if _ _ name__ ='_ _ main__': username=input ('Please enter your user name:') pwd=input ('Please enter your password:') if 'admin'==username and' admin'==pwd: print ('login succeeded!') Write_logininfo (username) # logging show_info () # prompts the user what to do num=int ('enter operation number:') while True: if num==0: print ('exit successful') break elif num==1: print ('view login log') Read_logininfo () # read date num=int (input ('input Operand number:') else: print ('you entered the wrong number!') Show_info () num = int (input ('enter Operand number:') else: print ('Sorry, the username or password is incorrect!') '' print (time.time ()) # seconds print (time.localtime (time.time () print (time.strftime ('% Y-%m-%d% HGV% MV% Scramco time.localtime (time.time () Task 2, simulate the automatic reply of Taobao customer service

At this point, I believe you have a deeper understanding of "how to record user login logs in python". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Development

Wechat

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

12
Report