python 登陸系統

2021-09-19 14:14:10 字數 2334 閱讀 5819

# 1.登入成功顯示歡迎頁面

# 2.登入失敗顯示密碼錯誤,並顯示錯誤幾次

# 3.登入三次失敗後,退出程式

# 1.可以支援多個使用者登入 

# 2.使用者3次認證失敗後,退出程式,再次啟動程式嘗試登入時,還是鎖定狀態

#3.可以建立使用者

#4.可以刪除使用者

#5.可以修改使用者

print('歡迎來到使用者登陸程式')

print('1.建立使用者')

print('2.登陸使用者')

print('3.刪除使用者')

print('4.修改使用者')

print('='*100)

choose = input('請選擇你的操作:')

#建立使用者

if choose == '1':

useradd = input('請輸入你要建立的唯一使用者:')

passwdad = input('請輸入你設定6位字母數字組合的密碼:')

with open('a', 'r', encoding='gbk') as f: #a 為當前目錄檔案

user = f.read()

if passwdad.isalnum() and len(passwdad) == 6 and useradd not in user:

with open ('a','a',encoding='gbk') as f:

f.write(useradd+passwdad+'\n')

#登陸使用者

if choose =='2':

j = 0

while true:

with open('a','r',encoding='gbk') as f:

user = f.read()

with open('b', 'r', encoding='gbk') as f:

nouser = f.read()

user1 = input('請輸入使用者:')

if user1 in nouser:

print('該使用者已鎖定')

break

if user1 not in user:

print('該使用者不存在')

break

passwd1 = input('請輸入密碼:')

if len(passwd1) != 6:

print('你二大爺的讓你輸入6位密碼')

break

if user1+passwd1 in user:

print('歡迎登陸')

break

if passwd1 not in user:

n = j+1

print('密碼輸入錯誤次數:')

print(n)

j +=1

if j == 3 :

print('該使用者已鎖定')

with open('b', 'a', encoding='gbk') as f: #b為當前目錄檔案

f.write(user1)

break

#刪除使用者

if choose == '3':

userdel = input('請輸入你要刪除的使用者名稱')

passwd = input('請輸入你要刪除的使用者密碼')

with open(r'a', 'r', encoding='gbk') as f:

l1 = f.readlines()

with open(r'a', 'w', encoding='gbk') as w:

for l in l1:

if userdel+passwd not in l:

w.write(l)

#修改使用者名稱

if choose == 4:

useradd1 = input('請輸入你要修改的使用者名稱:')

passwd1 = input('請輸入你要改型別的密碼:')

useradd2 = input('請輸入你要修改的使用者名稱:')

passwd2 = input('請輸入你要修改的使用者密碼:')

i = useradd1+passwd1

j = useradd2+passwd2

with open(r'a', 'r', encoding='gbk') as f:

l1 = f.readlines()

with open(r'a', 'w', encoding='gbk') as w:

for l in l1:

if i not in l:

w.write(l)

else:

w.write(j)

登陸系統 2

從配置檔案讀取config檔案內容 舉例 cstring inifile,password,userid getcurrentdirectory max path,inifile.getbuffer max path inifile.releasebuffer inifile config.ini ...

模擬登陸系統

模擬登陸系統主要練習檔案的操作 條件語句 迴圈等 知識點 1.str.strip chars 刪除字串前邊和後邊的所有空格,chars引數可以定製需要刪除的字元,可選。input strip 可以去除使用者輸入時帶入的空格,避免產生不必要的錯誤。用法 account input 請輸入賬號 stri...

自動登陸系統

自動登陸系統 第一種方法 執行regedit命令,開啟登錄檔編輯器,在左側窗格中依次定位到 hkey local machine software microsoft windows nt currentversion winlogon 子鍵,在右側窗格中找到 autoadminlogon 鍵值項並...