I am making a password generator in python. So what i want my code to do is take the website name from me and generate a random password and then save the website name password alongside each other in an excel sheet. the problem is that when i run the code the website gets saved but the password doesn't. Here is the code:
import random
import pyperclip
def generate_password():
password = ''
for x in range(0,int(n_of_char)):
password = password + random.choice(characters)
print(password)
pyperclip.copy(password)
print('this is a password generating application')
characters = 'qwrtyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890-=!@#$%^&*()__+":;|[]'
n_of_char = input('number of characters in your password: ')
website_name = input('website name: ')
wb = xl.load_workbook('password_database.xlsx')
sheet = wb['Sheet1']
for row in range(2, sheet.max_row + 2):
password = ''
cell = sheet.cell(row, 1)
if website_name == cell.value:
ask_permission = input('the website which you have entered already has a password in the database. Do you want to replace the password?')
current_row = row
if ask_permission == 'y':
generate_password()
another_cell = sheet.cell(current_row,2)
another_cell.value = password
break
else:
print('the password was not replaced')
break
elif cell.value == None:
generate_password()
cell.value = website_name
pass_cell = sheet.cell(row, 2)
pass_cell.value = password
break
wb.save('password_database.xlsx')