python使用者登入註冊 檔案讀寫 指標運用

2021-10-11 14:39:03 字數 1978 閱讀 8475

# -*- coding: utf-8 -*-

from os.path import isfile

class user:

def __init__(self, username, passwd, file_info):

self.user = username

self.pwd = passwd

self.file_db = file_info

def file_oper(file, mode, *args):

if mode == 'a+':

data = args[0]

with open(file, mode) as f:

f.write(data)

elif mode == 'r':

with open(file, mode) as f:

data = f.read()

return data

# 該部分要求實現註冊功能,要異常捕獲實現註冊成功,出錯,及使用者名稱已存在提示

def regist(self):

list_user =

if isfile(self.file_db):

with open(self.file_db, 'r') as f:

for line in f:

username = line.strip().split(':')[0]

if self.user not in list_user:

try:

with open(self.file_db, 'a+') as f:

user_info = '%s:%s\n' %(self.user, self.pwd)

f.write(user_info)

print('\033[32;1m註冊成功。\033[0m')

except exception as e:

print('error: ', e)

else:

print('\033[31;1m該使用者已存在.\033[0m')

def login(self):

list_user =

u_list = '%s:%s' %(self.user, self.pwd)

with open(self.file_db, 'r') as f:

for line in f:

if u_list in list_user:

print('\033[32;1m登入成功.\033[0m')

else:

print('\033[31;1m使用者名稱或密碼錯誤.\033[0m')

def start():

while true:

print('1. 註冊\n'

'2. 登入\n'

'3. 退出')

choice = input('>>>').strip()

if choice.isdigit() and 0 < int(choice) < 4:

if choice == '1':

username = input('使用者名稱:').strip()

passwd = input('密碼:').strip()

user = user(username, passwd, 'user.db')

user.regist()

elif choice == '2':

username = input('使用者名稱:').strip()

passwd = input('密碼:').strip()

user = user(username, passwd, 'user.db')

user.login()

elif choice == '3':

break

else:

print('輸入錯誤.')

if __name__ == '__main__':

start()

註冊檔案型別,關聯檔案

bool function registerfiletype lpctstr houzhui,lpctstr fmiaoshu,lpctstr wmiaoshu,lpctstr filepath hkey hkey null dword dwdip 0 lptstr newreg new tchar...

使用者註冊登入 和 資料寫入檔案的註冊登入

class user def init self,username,password self.username username self.password password class account def init self self.user list 目的是儲存使用者資訊 pass de...

某影視軟體asp註冊檔案

分析了某影視軟體。把asp檔案放在其根目錄下就可以了 1.3版本的註冊檔案reg1.3.asp,這個會自動把註冊碼寫入資料庫中 code start function getdiskid on error resume next getdiskid md5 ayang 19820504 reques...