3 17左右 函式註冊 登入 使用者認證

2022-08-17 23:00:18 字數 1605 閱讀 2490

# 編寫檔案修改功能,呼叫函式時,傳入三個引數(修改的檔案路徑,要修改的內容,修改後的內容)既可完成檔案的修改
def file(filename,old, new):

import os

with open(r'{}'.format(filename),mode='rb') as f1, \

open(r'健康.mp4', mode='wb') as write_f2:

for line in f1:

res = line.replace(old, new)

f1.write(res)

os.remove(file)

os.rename('健康.mp4', file)

編寫tail工具

import time

def tail():

with open("aaa.txt","rb") as f:

f.seek(0,2)

while true:

line = f.readline()

if len(line) == 0:

time.sleep(0.3)

else:

print(line.decode('utf-8'), end='')

# 3、編寫登入功能

def register():

user_info={}

with open('register.txt','at',encoding='utf-8')as f:

for line in f:

name,psw=line.strip().split(':')

user_info[name]=psw

whlie true:

username=input('請輸入您的使用者名稱').strip()

if username not in user_info:

print('使用者不存在請重新輸入')

continue

userpsd=input('請輸入密碼').strip()

if userpsd==user_info.get(username):

print('登入成功')

break

else:

print('登入失敗!')

4、編寫註冊

def login():

with open('ttt.txt','a')as f1,\

open('into.txt','r')as f2:

inp_name=input('請輸入使用者名稱:').strip()

inp_word=input('請輸入密碼:').strip()

for line in f2:

name,word=line.strip().split(':')

if inp_name==name:

return('該使用者名稱已被註冊')

else:

f1.write(':\n'.format(name=inp_name,psw=inp_word))

return ('註冊成功')

local sytem獲取登入使用者操作登錄檔

windows系統服務程序的使用者為local system,具有超級管理員許可權,不屬於某乙個使用者,因此在批處理檔案中無法使用 username 來獲取當前登入的使用者名稱,無法操作當前使用者的檔案路徑c users sytem程序如何獲取當前登入使用者名稱並操作hkcu?則需要做乙個對映,通過...

函式登入註冊事例

1 usr bin env python32 conding utf 8 3 author liudong 45 6def login username,password 7 8用於使用者登入 9 param username 10 param password 11 return true,登入成...

登入註冊介面函式

from tkinter import from pymssql import import tkinter.messagebox as mb defsql1 self 用於查詢 有返回值 ip 127.0.0.1 username sa password lzyft1030 con connect...