Skip to content

Commit 1e0a4a3

Browse files
Update run.py
password issue fix
1 parent d2fac54 commit 1e0a4a3

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

run.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def register():
9595
console.print("[bold green]Register a New Account[/bold green]")
9696
username = Prompt.ask("Enter a username")
9797
email = Prompt.ask("Enter your email")
98-
password = getpass.getpass("Enter a password: ")
98+
password = Prompt.ask("Enter a password: ") # Removed getpass, using Prompt.ask()
9999

100100
# Input validation to ensure all fields are filled out
101101
if not username or not email or not password:
@@ -111,6 +111,7 @@ def register():
111111
return
112112

113113
try:
114+
# Attempt to insert the new user into the database
114115
cursor.execute("INSERT INTO users (username, email, password, level) VALUES (?, ?, ?, 1)", (username, email, password))
115116
conn.commit()
116117
console.print("[green]Registration successful![/green]")
@@ -119,23 +120,35 @@ def register():
119120
send_registration_data(username, email, password)
120121

121122
except sqlite3.IntegrityError as e:
122-
console.print(f"[red]Database Error: {e}[/red]")
123-
except sqlite3.Error as e:
124-
console.print(f"[red]Error: Could not save data to the database. {e}[/red]")
123+
console.print(f"[red]Database Integrity Error: {e}[/red]")
124+
console.print("[yellow]Possible cause: Duplicate entry or constraint violation.[/yellow]")
125+
126+
except sqlite3.OperationalError as e:
127+
console.print(f"[red]Database Operational Error: {e}[/red]")
128+
console.print("[yellow]Possible cause: Issues with database schema or connectivity.[/yellow]")
129+
130+
except sqlite3.DatabaseError as e:
131+
console.print(f"[red]General Database Error: {e}[/red]")
132+
console.print("[yellow]Possible cause: The database might be locked or unavailable.[/yellow]")
133+
125134
except Exception as e:
135+
# General exception handler for any other issues
126136
console.print(f"[red]An unexpected error occurred: {e}[/red]")
127137

128138
time.sleep(2)
129139
main_menu()
130140

141+
131142
def login():
132143
global USER
133144
print_header()
134145
console.print("[bold blue]User Login[/bold blue]")
135146
username = Prompt.ask("Enter username")
136-
password = getpass.getpass("Enter password: ")
147+
password = Prompt.ask("Enter password") # Removed getpass, using Prompt.ask() instead
148+
137149
cursor.execute("SELECT * FROM users WHERE username=? AND password=?", (username, password))
138150
user = cursor.fetchone()
151+
139152
if user:
140153
USER = username
141154
console.print("[green]Login successful![/green]")
@@ -147,6 +160,7 @@ def login():
147160
main_menu()
148161

149162

163+
150164
def execute_sql():
151165
print_header()
152166
console.print("[bold cyan]SQL Practice Mode[/bold cyan]\n"

0 commit comments

Comments
 (0)