geekcomputers / geekcomputers/Python
Need help with a error in my code, that i cannot see for my self! sorry as it may be me being stupid
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 35.4k
- Forks
- 12.9k
- Avg merge
- 2h 37m
- Merged PRs (30d)
- 1
Description
So, i have been making my own login system, and saving it to a txt file. i have completed the basic's nearly, Login, Register, and now i am trying to add a forget password and username functions. so basically i have a if statement that checks if the user name is in one of the files. and then sends a recovery code. well for this case its a var assigned to randint(1000,9999) thats to reset the password. then i thought what if the user forgets there username, well you get them to insert there email they signed up with and if it matches a account(in one of the saved files) it sends a code to that email(console). Reset password works fine, but trying to find the players username is hard one, im not directly trying to match the email with the username, im trying to read the file for a email that matches one that is saved. and then will pull there username after, but i havent got that far yet, as when i enter a email its not finding it, instead its finding the username, could somone please help. it could be a small error i cannot see because its so late, and im so tired, but any help would be much appreciated thx.
`import tkinter
from tkinter import*
import os
import random
from random import randint
def register_user():
username_info = username.get()
password_info = password.get()
email_info = email.get()
file=open(username_info, 'w')
file.write(username_info+'\n')
file.write(password_info+'\n')
file.write(email_info)
file.close()
username_entry.delete(0, END)
password_entry.delete(0, END)
email_entry.delete(0, END)
Label(screen1, text = 'Registration susccesful', fg = 'green', font = ('calibri', 11)).pack()
def login_verify():
username1 = username_verify.get()
password1 = password_verify.get()
username_entry1.delete(0, END)
password_entry1.delete(0, END)
list_of_files = os.listdir()
if username1 in list_of_files:
file1 = open(username1, 'r')
verify = file1.read().splitlines()
if password1 in verify:
print('Login Sucess')
else:
print('password incorrect')
else:
print('username incorrect')
def codeS():
global code
code = randint(1000, 9999)
def submit_code():
code1 = code_verify.get()
password_code.delete(0, END)
if int(code1) == code:
Label(screen4, text='Code Correct', bg='green').pack()
else:
Label(screen4, text='Wrong Code', bg='red').pack()
def change_password():
global code_verify
global password_code
code_verify = StringVar()
username2 = username_verify2.get()
username_entry2.delete(0, END)
list_of_files = os.listdir()
if username2 in list_of_files:
file2 = open(username2, 'r')
verify1 = file2.read().splitlines()
codeS()
print(code)
Label(screen4, text='Reset Code Sent').pack()
password_code = Entry(screen4, textvariable = code_verify)
password_code.pack()
Label(screen4, text='').pack()
Button(screen4, text='Submit Code', width = 10, height = 2, command=submit_code).pack()
else:
Label(screen4, text='').pack()
Label(screen4, text='No matching user name').pack()
def find_username1():
global code_verify2
global username_code
code_verify2 = StringVar()
email2 = email_verify1.get()
email_entry1.delete(0, END)
list_of_files = os.listdir()
if email2 in list_of_files:
file3 = open(email2, 'r')
verify3 = file3.read().splitlines()
print('found')
else:
Label(screen5, text='').pack()
Label(screen5, text='No matching email').pack()
def register():
global screen1
screen1 = Toplevel(screen)
screen1.title('Register')
screen1.geometry('300x250')
global username
global password
global email
global username_entry
global password_entry
global email_entry
username = StringVar()
password = StringVar()
email = StringVar()
Label(screen1, text = 'Please enter details bellow').pack()
Label(screen1, text = '').pack()
Label(screen1, text = 'Username *').pack()
username_entry = Entry(screen1, textvariable = username)
username_entry.pack()
Label(screen1, text = 'Password *').pack()
password_entry = Entry(screen1, textvariable = password)
password_entry.pack()
Label(screen1, text = 'Email *').pack()
email_entry = Entry(screen1, textvariable = email)
email_entry.pack()
Label(screen1, text = '').pack()
Button(screen1, text = 'Register', width = 10, height = 1, command = register_user).pack()
def reset_password():
global screen4
screen4 = Toplevel(screen)
screen4.title('Reset Password')
screen4.geometry('300x250')
Label(screen4, text='Enter username *', height = 2, width = 30).pack()
global username_entry2
global username_verify2
username_verify2 = StringVar()
username_entry2 = Entry(screen4, textvariable = username_verify2)
username_entry2.pack()
Label(screen4, text='').pack()
Button(screen4, text='Reset Password', command=change_password).pack()
def forgot_user():
global screen5
screen5 = Toplevel(screen)
screen5.title('Find Username')
screen5.geometry('300x250')
Label(screen5, text='Enter Email *', height=2, width=30).pack()
global email_entry1
global email_verify1
email_verify1 = StringVar()
email_entry1 = Entry(screen5, textvariable = email_verify1, width=30)
email_entry1.pack()
Label(screen5, text='').pack()
Button(screen5, text='Find Username', command=find_username1).pack()
def login_issue():
global screen3
screen3 = Toplevel(screen)
screen3.title('Login Issues')
screen3.geometry('350x250')
Label(screen3, text='Have you forgot your username or password?', bg = 'grey', width = '350', height = '2', font = ('Calibri', 13)).pack()
Label(screen3, text = '').pack()
Button(screen3, text = 'Username', width = 30, height = 2, command = forgot_user).pack()
Label(screen3, text = '').pack()
Button(screen3, text = 'Password', width = 30, height = 2, command = reset_password).pack()
def login():
global screen2
screen2 = Toplevel(screen)
screen2.title('Login')
screen2.geometry('300x250')
Label(screen2, text = 'Please enter details bellow to login').pack()
Label(screen2, text = '').pack()
global username_verify
global password_verify
username_verify = StringVar()
password_verify = StringVar()
global username_entry1
global password_entry1
Label(screen2, text = 'Username * ').pack()
username_entry1 = Entry(screen2, textvariable = username_verify)
username_entry1.pack()
Label(screen2, text = '').pack()
Label(screen2, text = 'Password * ').pack()
password_entry1 = Entry(screen2, textvariable = password_verify)
password_entry1.pack()
Label(screen2, text = '').pack()
Button(screen2, text = 'Login', width = 10, height = 1, command = login_verify).pack()
Label(screen2, text = '').pack()
Button(screen2, text = 'Login issue?', width = 10, height = 1, command=login_issue).pack()
def main_screen():
global screen
screen = Tk()
screen.geometry('300x250')
screen.title('Login API 1.2')
Label(text = 'Login 1.2', bg = 'grey', width = '300', height = '2', font = ('Calibri', 13)).pack()
Label(text = '').pack()
Button(text = 'Login', height = '2', width = '30', command=login).pack()
Label(text = '').pack()
Button(text = 'Register', height = '2', width = '30', command=register).pack()
screen.mainloop()
main_screen()
`
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The relevant entry point is find_username1() in the supplied script; compare its lookup with register_user(), which writes the username, password, and email into files named by username. Run the forgot-username flow with a registered account and make the completed behavior identify the username associated with the entered email.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100