Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Csproject

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

PM SHRI KendriyaVidyalya no.

2
Satna,(M.P.)

Session:-2023-24

C.S Project Work

Topic:-‘Library Mnagement System’

Submi ed to:- Submi ed By :-


Mr.Neeraj Kumar Ambuj Singh
(PGT English) Roll No. 04
Class- XII ‘A’
Acknowledgement

I would like to take this opportunity to acknowledge


everyone who has helped me in every stage of this
project.
I am deeply indebted to my C.S teacher, Mr. Vivek
Sharma for his guidance and suggestions in
completing this project. The completion of this project
was possible under his guidance and support.
I am also very thankful to my parents and my friends
who have boosted me up morally with their continuous
support.
At last but not least, I am very thankful to God
almighty for showering his blessings upon me.

Thank You!!
Introduction:
The Library Management System (LMS) is an
automated solution designed to streamline the
management of books and resources in a library.

Project Objectives:
- Automate book management processes.
- Provide secure user authentication.
- Integrate with a database for data storage.
- Create a user-friendly GUI for interaction.

System Requirements:
- Python 3.x
- Tkinter (for GUI)
- SQLite (for database)
Features:
- User Authentication
- Book Management (Add, Borrow, Return)
- Database Integration
- Graphical User Interface (GUI)
- Error Handling

System Architecture:
- User interacts with the GUI.
- GUI communicates with the Library and
UserAuthentication classes.
- The Library class interacts with the SQLite
database.

User Roles:
- Admin (Librarian)
- Can access all features.
- Library User
- Can borrow and return books.
Implementation Details:
a. User Authentication:
- SQLite database stores hashed user
credentials.
- Bcrypt used for password hashing.
- Credentials validated during login.
b.Database Integration:
- SQLite database for storing book details.
- SQL queries used for CRUD operations.
c. Library Class:
- Book and Library classes handle book-related
operations.
- Methods include add_book, display_books,
borrow_book, and return_book.
d. GUI Design:
- Tkinter used for GUI development.
- Login screen with username and password
fields.
- Main interface with a listbox and buttons.
e. Error Handling:
- User-friendly error messages for invalid
actions.
- Exception handling for unexpected issues.

Testing and Validation:


- Unit testing for each function and method.
- Validate user authentication and book
management.
Source Code-
import sqlite3
from tkinter import Tk, Label, Entry, Button,
Listbox, messagebox
from getpass import getpass
from bcrypt import hashpw, gensalt, checkpw

class Book:
def __init__(self, title, author, ISBN, copies):
self.title = title
self.author = author
self.ISBN = ISBN
self.copies = copies
self.available_copies = copies

class Library:
def __init__(self):
self.books = []
def add_book(self, book):
self.books.append(book)

def display_books(self):
return self.books

def borrow_book(self, title):


for book in self.books:
if book.title == title and book.available_copies
> 0:
book.available_copies -= 1
return f"Book '{title}' borrowed
successfully."
return f"Book '{title}' not available for
borrowing."

def return_book(self, title):


for book in self.books:
if book.title == title and book.available_copies
< book.copies:
book.available_copies += 1
return f"Book '{title}' returned
successfully."
return f"Error: Book '{title}' not found or
already available."

class UserAuthentication:
def __init__(self, db_path='library.db'):
self.conn = sqlite3.connect(db_path)
self.cursor = self.conn.cursor()
self.create_user_table()

def create_user_table(self):
self.cursor.execute('''CREATE TABLE IF NOT
EXISTS users (username TEXT, password TEXT)''')
self.conn.commit()

def register_user(self, username, password):


hashed_password =
hashpw(password.encode('utf-8'), gensalt())
self.cursor.execute("INSERT INTO users
VALUES (?, ?)", (username, hashed_password))
self.conn.commit()

def login(self, username, password):


self.cursor.execute("SELECT password FROM
users WHERE username=?", (username,))
result = self.cursor.fetchone()
if result and checkpw(password.encode('utf-8'),
result[0]):
return True
return False

class LibraryApp:
def __init__(self, master, library, auth):
self.master = master
self.master.title("Library Management System")

self.label = Label(master, text="Library


Management System")
self.label.pack()
self.username_label = Label(master,
text="Username:")
self.username_label.pack()
self.username_entry = Entry(master)
self.username_entry.pack()

self.password_label = Label(master,
text="Password:")
self.password_label.pack()
self.password_entry = Entry(master, show="*")
self.password_entry.pack()

self.login_button = Button(master, text="Login",


command=self.login)
self.login_button.pack()

self.books_listbox = Listbox(master)
self.books_listbox.pack()

self.borrow_button = Button(master,
text="Borrow Book", command=self.borrow_book)
self.borrow_button.pack()

self.return_button = Button(master,
text="Return Book", command=self.return_book)
self.return_button.pack()

self.library = library
self.auth = auth
self.init_books()

def init_books(self):
book1 = Book("Introduction to Python", "John
Smith", "123456789", 5)
book2 = Book("Data Structures in Python",
"Jane Doe", "987654321", 3)
self.library.add_book(book1)
self.library.add_book(book2)
self.update_books_listbox()

def update_books_listbox(self):
self.books_listbox.delete(0, "end")
for book in self.library.display_books():
self.books_listbox.insert("end", f"{book.title}
- {book.available_copies} available")

def login(self):
entered_username = self.username_entry.get()
entered_password = self.password_entry.get()

if self.auth.login(entered_username,
entered_password):
self.show_message("Login Successful")
self.show_books()
else:
self.show_message("Invalid Credentials")

def borrow_book(self):
selected_index =
self.books_listbox.curselection()
if selected_index:
selected_book =
self.library.display_books()[selected_index[0]]
result =
self.library.borrow_book(selected_book.title)
self.show_message(result)
self.update_books_listbox()
else:
self.show_message("Select a book to
borrow")

def return_book(self):
selected_index =
self.books_listbox.curselection()
if selected_index:
selected_book =
self.library.display_books()[selected_index[0]]
result =
self.library.return_book(selected_book.title)
self.show_message(result)
self.update_books_listbox()
else:
self.show_message("Select a book to return")

def show_message(self, message):


messagebox.showinfo("Library Management
System", message)

if __name__ == "__main__":
# Create SQLite database and table for users
(dummy data for illustration)
conn = sqlite3.connect('library.db')
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS
users (username TEXT, password TEXT)''')
c.execute("INSERT OR IGNORE INTO users
VALUES ('admin',
'$2b$12$Z8TWd.1myfmy.SqWUzqTpOmDrWVeqom
5LoI0ADMPuV19QhJlcs75y')")
conn.commit()
conn.close()
root = Tk()
auth = UserAuthentication()
library = Library()
app = LibraryApp(root, library, auth)
root.mainloop()
Conclusion:
- The LMS simplifies library operations, improving
efficiency and user experience.
- Challenges included securing user data and
ensuring smooth database interactions.

Future Enhancements:
- Implement multi-user support.
- Add search and sorting features for books.
- Explore the possibility of integrating with an
online book database.
BIBLIOGRAPHY :-
 Sunita Arora – Comptuter Science with Python
 Preeti Arora – Comptuter Science with Python
 www.Github.com

You might also like