如何使用内置的Python 3.5模块为登录脚本创建数据库

我想知道如何不用保存到文件,而是保存到大量用户的数据库/文件。 > 50.如何使用内置的Python 3.5模块为登录脚本创建数据库

保存到文件的部分是下面:

def FSSignup():#This defines FSSignup 

with open(creds, 'w') as f:

f.write(nameE.get())

f.write('\n')

f.write(pwordE.get())

f.close()

roots.destroy()

login()

这是我的主要代码:

from tkinter import * 

import os

creds = "tempfile.temp"

def signup():

global pwordE

global nameE

global roots

roots = Tk()

roots.title("Signup")

instructions = Label(roots, text="Please enter new credentials:")

instructions.grid(row=0, column=0, sticky=E)

nameL = Label(roots, text="New Username")

pwordL = Label(roots, text = "New Password")

nameL.grid(row=1, column=0, sticky=W)

pwordL.grid(row=2, column=0, sticky=W)

nameE = Entry(roots)

pwordE= Entry(roots, show='"')

nameE.grid(row=1, column=1)

pwordE.grid(row=2, column=1)

signupB = Button(roots, text="Signup", command=FSSignup)

signupB.grid(columnspan=2, sticky=W)

roots.mainloop()#

def FSSignup():

with open(creds, 'w') as f:

f.write(nameE.get())

f.write('\n')

f.write(pwordE.get())

f.close()

roots.destroy()

login()

def login():

global nameEL

global pwordEL

global rootA

rootA = Tk()

rootA.title("Login")

instruction = Label(rootA, text="Enter your credentials")

instruction.grid(sticky=E)

nameL = Label(rootA, text="Username")

pwordL = Label(rootA, text="Password")

nameL.grid(row=1, sticky=W)

pwordL.grid(row=2, sticky=W)

nameEL = Entry(rootA)

pwordEL = Entry(rootA, show='"')

nameEL.grid(row=1, column=1)

pwordEL.grid(row=2, column=1)

loginB = Button(rootA, text="Login", command=CheckLogin)

loginB.grid(columnspan=2, sticky=W)

rmuser = Button(rootA, text="Delete User", fg="red", command=DelUser)

rmuser.grid(columnspan=2, sticky=W)

rootA.mainloop()

def CheckLogin():

with open(creds) as f:

data = f.readlines()

username = data[0].rstrip()

pword = data[1].rstrip()

if nameEL.get() == username and pwordEL.get() == pword:

r =Tk()

r.title("Successful Login")

r.geometry("150x50")

rL = Label(r, text="\n[+]Logged In")

rL.pack()

r.mainloop()

else:

r =Tk()

r.title("Invalid Login")

r.geometry("150x50")

rL = Label(r, text="\n[+]Invalid Login")

rL.pack()

r.mainloop()

def DelUser():

os.remove(creds)

rootA.destroy

signup()

if os.path.isfile(creds):

login()

else:

signup()

回答:

SQLite是标准库的一部分 - https://docs.python.org/3.5/library/sqlite3.html

以上是 如何使用内置的Python 3.5模块为登录脚本创建数据库 的全部内容, 来源链接: utcz.com/qa/266409.html

回到顶部