Skip to content

Commit

Permalink
Merge pull request #184 from Ankush0286/main
Browse files Browse the repository at this point in the history
Added asterisk Masking in password
  • Loading branch information
07sumit1002 authored Oct 5, 2024
2 parents 24ae47d + 616f1ad commit 06d373d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion DBSetup/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ def main():
time.sleep(1)
sys.exit(0)

# Function to securely fetch MySQL password from user with asterisk masking
def get_mysql_password():
print(Fore.YELLOW + "Enter your MySQL Password: " + Fore.RESET, end='', flush=True)
password = ''
while True:
key = keyboard.read_event()
if key.event_type == keyboard.KEY_DOWN:
if key.name == 'enter':
print() # Move to the next line after pressing enter
break
elif key.name == 'backspace':
if password:
password = password[:-1] # Remove last character from password
print('\b \b', end='', flush=True) # Erase the last asterisk
elif key.name in ('space', 'tab'):
continue # Ignore space and tab
else:
password += key.name # Add the character to the password
print('*', end='', flush=True) # Print an asterisk for masking

return password

# Placeholder function for setting up database from scratch
def setup_database_from_scratch():
Expand Down Expand Up @@ -155,5 +176,5 @@ def reset_database():
print(Fore.GREEN + "Database Reset complete." + Fore.RESET)

if __name__ == "__main__":
passwd = input(Fore.YELLOW + "Enter your MySQL Password: " + Fore.RESET)
passwd = get_mysql_password() # Using custom function for password input
main()

0 comments on commit 06d373d

Please sign in to comment.