Я пытаюсь создать систему регистрации / входа для проекта python, над которым я работаю. Вот весь код
def signup():
usrname = input("Enter new username: ")
password = input("Enter new password: ")
try:
f = open("id.txt", "x")
f.write(usrname)
f.write("\n")
f.write(password)
f.close()
except Exception as e:
print(e)
print("Now Log In")
login()
def login():
usrname_1 = input("Enter username: ")
password_2 = input("Enter password: ")
f = open("id.txt")
lines = f.readlines()
if usrname_1 == lines[0] and password_2 == lines[1]:
print("Succesfully Logged in")
else:
print("Username or Password Invalid")
ask1 = input("Sign UP or Login: ").lower()
if ask1 == "sign up":
signup()
else:
login()
def main():
import pyttsx3
import datetime
import random
import sys
import time
import webbrowser
import os
import wikipedia
import smtplib
engine = pyttsx3.init('sapi5')
def speak(audio):
rate = engine.getProperty('rate')
print(rate)
engine.setProperty('rate', 100)
engine.say(audio)
engine.runAndWait()
def wishme():
name = "My name"
ri = random.randint(0, 2)
greet = ['Hello', 'Hi', 'Hola']
speak(greet[ri])
hour = int(datetime.datetime.now().hour)
if 0 <= hour < 12:
speak("Good Morning" + name)
elif 12 <= hour < 18:
speak("Good Afternoon" + name)
else:
speak("Good Evening" + name)
speak("What can I do for you? ")
def internet():
b = input("Which website do u wnat to open:")
if 'open youtube' in b:
webbrowser.open("https://www.youtube.com/")
elif 'open facebook' in b:
webbrowser.open("https://www.facebook.com/")
elif 'open chess' in b:
webbrowser.open("https://www.chess.com/")
elif 'open chat bot' in b:
webbrowser.open("https://www.cleverbot.com/?2")
elif 'open google' in b:
webbrowser.open("https://www.google.co.in/")
elif 'open stack overflow' in b:
webbrowser.open("https://stackoverflow.com/users/13997576/unknown-12")
elif 'open free fall tournament' in b:
webbrowser.open("https://www.freefalltournament.com/")
elif 'open mail' in b:
webbrowser.open("https://www.rediff.com/login")
elif 'open photo editor' in b:
speak("Which one PhotoPea or P I X L R")
c = input("Which one: ")
if c == "PhotoPea":
webbrowser.open("https://pixlr.com/e/")
else:
webbrowser.open("https://www.photopea.com")
elif 'can you open' in b:
print("I can open any website you want")
speak("I can open any website you want")
else:
speak("Sorry for this but i can't open the web")
time.sleep(0.2)
speak("Opening google so you can phsically search there")
webbrowser.open("https://www.google.com/")
def openapp():
speak("Which app i should open for you")
time.sleep(0.2)
speak("I will open apps from your device")
d = input("Which app to open: ( pycharm, sublime text, music player, chrome, calculator )")
if "pycharm" in d:
os.startfile("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe")
elif "sublime text" in d:
os.startfile("C:\\Program Files\\Sublime Text 3\\sublime_text.exe")
elif "music player" in d:
ee = input("Which one: ( aimp or default )")
if "aimp" in ee:
os.startfile("E:\\AIMP\\AIMP.exe")
else:
os.startfile("C:\\Program Files\\Windows Media Player\\wmplayer.exe")
elif "calculator" in d:
os.startfile("C:\\Windows\\System32\\calc.exe")
else:
speak("Cannot find application.... You can open it manually. Opening explorer")
os.startfile("C:\\Windows\\explorer.exe")
def wiki():
speak("What can i search on wikipedia?")
f = input("What should i search:")
results = wikipedia.summary(f, sentences=2)
speak("According to Wikipedia" + results)
print("According to wikipedia" + results)
def saytime():
currenttime = datetime.datetime.now().strftime("%H " + "hours " + "%M" + "Minutes")
speak("Currently it is" + currenttime)
print(currenttime)
def songs():
speak("Playing songs")
music_dir = "E:\\Creations\\Songs.p\\PaLaAsH_SoNgS"
randIndex = random.randint(0, 99)
songs = os.listdir(music_dir)
print(songs)
os.startfile(os.path.join(music_dir, songs[randIndex]))
def help1():
pass
def intro():
speak("I am Spectron. A basic level A.I Which can do anything for you!")
time.sleep(0.5)
speak("Type help for more information")
def game():
game_List = ['Chess', 'Cards', 'Minesweepers', 'Purble Place', 'Mahjong titans']
print(game_List)
gamer_inp = input("Which game would you like to play: ").lower()
if 'chess' in gamer_inp:
os.startfile("C:\\Program Files\\Microsoft Games\\Chess\\Chess.exe")
elif 'cards' in gamer_inp:
os.startfile("C:\\Program Files\\Microsoft Games\\Solitaire\\Solitaire.exe")
elif 'minesweepers' in gamer_inp:
os.startfile("C:\\Program Files\\Microsoft Games\\Minesweeper\\MineSweeper.exe")
elif 'purble place' in gamer_inp:
os.startfile("C:\\Program Files\\Microsoft Games\\Purble Place\\PurblePlace.exe")
elif 'mahjong titans' in gamer_inp:
os.startfile("C:\\Program Files\\Microsoft Games\\Mahjong\\Mahjong.exe")
else:
speak("Cannot open game for you")
time.sleep(0.5)
speak("Opening Explorer so you can find there")
os.startfile("C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Games")
def opendir():
os.startfile("E:\\Creations")
def sp():
pass
def sendemail(to, content):
server = smtplib.SMTP('smtp.rediffmail.com', 25)
server.ehlo()
server.starttls()
server.login('mailid', 'pass')
server.sendmail('mymail', to, content)
server.close()
if __name__ == '__main__':
wishme()
intro()
while True:
usr_input = input("What can i do:")
if 'internet' in usr_input or 'open internet' in usr_input:
internet()
elif 'open app' in usr_input or 'app' in usr_input:
openapp()
elif 'wikipedia' in usr_input or 'search wikipedia' in usr_input:
wiki()
elif ' what time' in usr_input or "the time" in usr_input:
saytime()
elif 'play songs' in usr_input or 'songs' in usr_input or 'song' in usr_input:
songs()
elif 'help' in usr_input:
help1()
elif 'play' in usr_input or 'play a game' in usr_input or 'game' in usr_input:
game()
elif 'open my working directory' in usr_input or 'working directory' in usr_input:
opendir()
elif 'store my password' in usr_input or 'store password' in usr_input:
sp()
elif 'email' in usr_input or 'send email' in usr_input:
try:
speak("What should i send?")
content = input("What would you like to say: ")
to = input("To whom you have to send this email: ")
sendemail(to, content)
speak("Email send successfully!")
except Exception as e:
print(e)
speak("I can't send email")
time.sleep(0.5)
speak("Opening mail. You can send manually through web")
webbrowser.open("https://www.rediff.com/login")
elif 'quit' in usr_input:
speak("Good Bye! Have a nice day")
time.sleep(1)
sys.exit()
else:
speak("This feature is not available")
`Я не подключал логин для входа в основную функцию. Но мой главный вопрос в том, что мне делать, чтобы создать систему входа / регистрации с использованием файла io. Я попытался использовать ввод данных пользователем, сохранить идентификатор и передать файл, и при входе в систему я получил доступ к файлу и получил конкретную строку в файле и проверял это, но всякий раз, когда я пытаюсь использовать это, это терпит неудачу! Можете ли вы порекомендовать мне способ решить эту проблему. ** Примечание: ** Пожалуйста, не рекомендуйте MySql.
Спасибо!