Professional Documents
Culture Documents
py:-
import sys
import mysql.connector
from PyQt5.QtWidgets import (
QApplication, QMainWindow, QPushButton, QLabel, QLineEdit, QVBoxLayout,
QWidget, QMessageBox, QTextEdit, QComboBox, QHBoxLayout, QGroupBox,
QRadioButton, QDialog
)
from PyQt5.QtGui import QFont, QIcon
from PyQt5.QtCore import Qt
from login import LoginWindow # Import the LoginWindow class from login.py
class PasswordManagerApp(QMainWindow):
def __init__(self):
super().__init__()
self.init_ui()
self.conn = self.connect_to_database()
self.create_password_table()
self.load_websites()
def init_ui(self):
self.setWindowTitle('Password Manager By Jujhar28')
self.setGeometry(100, 100, 400, 400)
self.layout = QVBoxLayout()
self.central_widget.setLayout(self.layout)
self.website_input = QComboBox()
self.new_website_input = QLineEdit()
self.username_input = QLineEdit()
self.password_input = QLineEdit()
self.password_input.setEchoMode(QLineEdit.Password)
self.layout.addWidget(self.website_label)
self.layout.addWidget(self.website_input)
self.layout.addWidget(self.new_website_label)
self.layout.addWidget(self.new_website_input)
self.layout.addWidget(self.username_label)
self.layout.addWidget(self.username_input)
self.layout.addWidget(self.password_label)
self.layout.addWidget(self.password_input)
self.layout.addWidget(self.add_button)
self.layout.addLayout(button_layout)
self.layout.addWidget(self.retrieve_button)
self.layout.addLayout(self.passwords_display)
self.add_button.clicked.connect(self.add_password)
self.edit_button.clicked.connect(self.edit_password)
self.delete_button.clicked.connect(self.delete_password)
self.retrieve_button.clicked.connect(self.retrieve_passwords)
self.website_input.currentIndexChanged.connect(self.on_website_changed)
def toggle_theme(self):
self.dark_mode = not self.dark_mode
if self.dark_mode:
# Dark mode styles
self.setStyleSheet("""
background-color: #333333;
color: #FFFFFF;
""")
else:
# Light mode styles
self.setStyleSheet("""
background-color: #FFFFFF;
color: #000000;
""")
def connect_to_database(self):
try:
conn = mysql.connector.connect(
host="localhost",
user="root",
password="jujh@r2831",
database="password_manager"
)
return conn
except Exception as e:
QMessageBox.critical(self, "Database Error", "Error connecting to
the database: " + str(e))
sys.exit(1)
def create_password_table(self):
cursor = self.conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS passwords (
id INT AUTO_INCREMENT PRIMARY KEY,
website VARCHAR(255) NOT NULL,
username VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL
)
""")
self.conn.commit()
def load_websites(self):
cursor = self.conn.cursor()
cursor.execute("SELECT DISTINCT website FROM passwords")
websites = cursor.fetchall()
self.website_input.clear()
self.website_input.addItem("New Website")
self.website_input.addItems([website[0] for website in websites])
def add_password(self):
website = self.website_input.currentText()
new_website = self.new_website_input.text()
username = self.username_input.text()
password = self.password_input.text()
if new_website:
cursor = self.conn.cursor()
cursor.execute("""
INSERT INTO passwords (website, username, password)
VALUES (%s, %s, %s)
""", (new_website, username, password))
self.conn.commit()
self.load_websites()
self.new_website_input.clear()
else:
QMessageBox.warning(self, "Input Error", "Please fill in all
fields.")
def edit_password(self):
website = self.website_input.currentText()
username = self.username_input.text()
password = self.password_input.text()
def delete_password(self):
website = self.website_input.currentText()
if website:
confirm = QMessageBox.question(self, "Confirm Deletion", f"Are you
sure you want to delete all passwords for {website}?", QMessageBox.Yes |
QMessageBox.No)
if confirm == QMessageBox.Yes:
cursor = self.conn.cursor()
cursor.execute("""
DELETE FROM passwords
WHERE website = %s
""", (website,))
self.conn.commit()
QMessageBox.information(self, "Success", f"All passwords for
{website} deleted successfully!")
self.load_websites()
else:
QMessageBox.warning(self, "Input Error", "Please select a website.")
def retrieve_passwords(self):
website = self.website_input.currentText()
if website:
cursor = self.conn.cursor()
cursor.execute("""
SELECT username, password FROM passwords
WHERE website = %s
""", (website,))
passwords = cursor.fetchall()
if passwords:
# Clear the previous display
for i in reversed(range(self.passwords_display.count())):
self.passwords_display.itemAt(i).widget().setParent(None)
if __name__ == "__main__":
app = QApplication(sys.argv)
main_window = PasswordManagerApp()
login_window = LoginWindow(main_window) # Pass main_window instance
if login_window.exec_() == QDialog.Accepted:
main_window.show()
sys.exit(app.exec_())
Login.py:-
class LoginWindow(QDialog):
def __init__(self, main_window):
super().__init__()
self.main_window = main_window
self.setWindowTitle("Login")
self.setGeometry(100, 100, 300, 150)
self.layout = QVBoxLayout()
self.setLayout(self.layout)
self.username_label = QLabel("Username:")
self.password_label = QLabel("Password:")
self.username_input = QLineEdit()
self.password_input = QLineEdit()
self.password_input.setEchoMode(QLineEdit.Password)
self.login_button = QPushButton("Login")
self.register_button = QPushButton("Register")
self.layout.addWidget(self.username_label)
self.layout.addWidget(self.username_input)
self.layout.addWidget(self.password_label)
self.layout.addWidget(self.password_input)
self.layout.addWidget(self.login_button)
self.layout.addWidget(self.register_button)
self.login_button.clicked.connect(self.login)
self.register_button.clicked.connect(self.register)
def login(self):
username = self.username_input.text()
password = self.password_input.text()
if self.main_window.verify_user(username, password):
self.accept()
else:
QMessageBox.warning(self, "Login Failed", "Invalid username or
password")
def register(self):
username = self.username_input.text()
password = self.password_input.text()
Use password_manager;
3.
4.
5.
6.
7.
8.
9.
10.
1. PyQt5 Documentation: PyQt5 is a powerful Python library for
creating desktop applications with a graphical user interface
(GUI). The official documentation is an invaluable resource for
understanding PyQt5's features and functionalities, making it an
essential reference for your project.
# Show the New Website input field when "New Website" is selected
if selected_website == "New Website":
self.new_website_label.show()
self.new_website_input.show()
else:
self.new_website_label.hide()
self.new_website_input.hide()
def main():
MySQL is an open-source, relational
database management system that plays
a crucial role in many software
applications, including our Password
Manager project. It is renowned for its
scalability, speed, and robust
performance, making it a popular choice
for businesses and developers.
Ackowledgement . . . . . . . . . 2.
Introduction To Project. . . . 3.
Introduction To Python. . . . 4.
Introduction To MySQL. . . . 5.
Project Code . . . . . . . . . . . . 5 - 15
Output. . . . . . . . . . . . . . . . . 15- 20
Bibliography . . . . . . . . . . . . 20-21
Our Password Manager application is designed to simplify
and secure the way users store and manage their online
credentials. In an era of countless accounts, it can be
challenging to remember unique passwords for each. This
project introduces users to Python and MySQL while
offering a convenient solution for password management.
With the Password Manager, users can: