Online Voting[4]
Online Voting[4]
1.INTRODUCTION
2.REQUIREMENTS
4.SOURCE CODE
5.OUTPUT
6.BIBLIOGRAPH
INTERFACE WITH
PYTHON
AND
MYSQL
INTRODUCTION
WHAT IS PYTHON?
Python is a high-level, interpreted programming
language known for its simplicity and readability.
Created by Guido van Rossum and first released in
1991, Python has since become one of the most
popular languages for both beginners and
experienced programmers alike.
Features of Python:
Future Trends:
Applications of SQL:
Trends in SQL:
Security:
Encryption: Secure transmission of votes.
Authentication: Strong verification of voters'
identities.
Access control: Prevent unauthorized access to the
voting system.
Accessibility:
User-friendly interface: Easy navigation for all
voters.
Compatibility: Accessible across various devices and
platforms.
Language support: Multilingual options for diverse
voters.
Integrity:
Voter anonymity: Ensuring the secrecy of individual
votes.
Auditability: Ability to verify the accuracy of results.
Tamper detection: Mechanisms to detect and
prevent manipulation of votes or results.
Reliability:
Redundancy: Backup systems to ensure continuous
operation.
Scalability: Ability to handle varying loads during
peak times.
Legal and Regulatory Compliance:
Compliance with election laws and regulations.
Data protection: Safeguarding voter information
and privacy.
Verification and Validation:
Contingency Planning:
Backup plans for technical failures or cyber attacks.
Contingency procedures for disputed or contested
results.
Implementing these requirements effectively is
crucial to the success and trustworthiness of online
voting systems.
ONLINE
VOTING
MACHINE
BRIEF OVERVIEW OF ONLINE VOTING MACHINE:
WHAT IS ONLINE VOTING?
Online voting, also known as e-voting or internet
voting, is a digital method of casting ballots in
elections or other voting processes using electronic
devices connected to the internet. This form of
voting offers convenience and accessibility, allowing
voters to participate from virtually anywhere with
an internet connection.
The process typically involves voters logging into a
secure online platform, verifying their identity
through various authentication measures, and
selecting their preferred candidates or options.
Votes are then encrypted and transmitted securely
to a central database for tabulation.
BENEFITS OF ONLINE VOTING:
Advocates of online voting highlight its potential to
increase voter turnout, particularly among
populations facing barriers to traditional voting
methods, such as those with disabilities or living
abroad. Additionally, online voting can streamline
the voting process, reduce costs associated with
traditional paper-based methods, and provide
faster election results.
However, online voting also raises concerns
regarding security, privacy, and integrity. Ensuring
the confidentiality and accuracy of votes in the face
of cyber threats is a significant challenge.
Furthermore, the potential for coercion,
manipulation, or technical malfunctions poses risks
to the integrity of elections conducted online.
Online voting provides greater access to the
electoral process for individuals who face barriers
to traditional voting methods, such as those with
disabilities, mobility issues, or living in remote
locations. It allows voters to cast their ballots
conveniently from any location with internet access,
reducing the need for physical transportation to
polling stations.
SOURCE CODE:
IN MYSQL:
CREATE DATABASE VotingMachine;
USE VotingMachine;
CREATE TABLE Users ( id INT PRIMARY KEY
AUTO_INCREMENT, username VARCHAR(255)
UNIQUE, passwordVARCHAR(255));
CREATE TABLE Candidates ( id INT PRIMARY KEY
AUTO_INCREMENT, name VARCHAR(255) UNIQUE);
CREATE TABLE Votes ( id INT PRIMARY KEY
AUTO_INCREMENT, user_id INT, candidate_id INT,
FOREIGN KEY (user_id) REFERENCES Users(id),
FOREIGN KEY (candidate_id) REFERENCES
Candidates(id));
IN PYTHON:
import mysql.connector
from getpass import getpass
# Connect to MySQL
db =
mysql.connector.connect(host="localhost",user="ro
ot",password="priya2006",database="VotingMachi
ne")
cursor = db.cursor()
# User Authentication
def login():
username = input("Enter your username: ")
password = getpass("Enter your password: ")
cursor.execute("SELECT * FROM Users WHERE
username = %s AND password = %s", (username,
password))
user = cursor.fetchone()
if user:
return user[0] # Return user_id
else:
print("Invalid username or password.")
return None
# Add a candidate
def add_candidate():
name = input("Enter candidate's name: ")
try:
cursor.execute("INSERT INTO Candidates
(name) VALUES (%s)", (name,))
db.commit()
print(f"Candidate '{name}' added
successfully!")
except mysql.connector.Error as err:
print(f"Error adding candidate: {err}")
db.rollback()
# Cast a vote
def vote(user_id):
cursor.execute("SELECT * FROM Candidates")
candidates = cursor.fetchall()
print("Available Candidates:")
for candidate in candidates:
print(f"{candidate[0]}. {candidate[1]}")
candidate_id = int(input("Enter the candidate ID
you want to vote for: "))
try:
cursor.execute("INSERT INTO Votes (user_id,
candidate_id) VALUES (%s, %s)", (user_id,
candidate_id))
db.commit()
print("Vote added successfully!")
except mysql.connector.Error as err:
print(f"Error voting: {err}")
db.rollback()
# Main program
while True:
print("\n1. Login\n2. Register\n3. Add
Candidate\n4. Vote\n5. Generate Results\n6. Exit")
choice = input("Enter your choice: ")
if choice == '1':
user_id = login()
if user_id:
print("Login successful!")
elif choice == '2':
register()
elif choice == '3':
add_candidate()
elif choice == '4':
if user_id:
vote(user_id)
else:
print("Please log in first.")
elif choice == '5':
generate_results()
elif choice == '6':
break
else:
print("Invalid choice. Please try again.")
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 2
Enter a new username: deepa
Warning: Password input may be echoed.
Enter a password: 123deepa
Registration successful.
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 2
Enter a new username: lavanya
Warning: Password input may be echoed.
Enter a password: lavanya1984
Registration successful.
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 2
Enter a new username: mythili
Warning: Password input may be echoed.
Enter a password: mythili1990
Registration successful.
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 2
Enter a new username: priya
Warning: Password input may be echoed.
Enter a password: 123priya
Registration successful.
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 3
Enter candidate's name: vijay
Candidate 'vijay' added successfully!
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 3
Enter candidate's name: dhoni
Candidate 'dhoni' added successfully!
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 1
Enter your username: thaman
Warning (from warnings module):
File
"C:\Users\HCL\AppData\Local\Programs\Python\Py
thon39\lib\getpass.py", line 100
return fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the
terminal.
Warning: Password input may be echoed.
Enter your password: 123thaman
Login successful!
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 4
Available Candidates:
2. dhoni
1. vijay
Enter the candidate ID you want to vote for: 1
Vote added successfully!
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 1
Enter your username: deepa
Warning: Password input may be echoed.
Enter your password: 123deepa
Login successful!
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 4
Available Candidates:
2. dhoni
1. vijay
Enter the candidate ID you want to vote for: 1
Vote added successfully!
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 1
Enter your username: lavanya
Warning: Password input may be echoed.
Enter your password: lavanya1984
Login successful!
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 4
Available Candidates:
2. dhoni
1. vijay
Enter the candidate ID you want to vote for: 2
Vote added successfully!
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 1
Enter your username: mythili
Warning: Password input may be echoed.
Enter your password: mythili1990
Login successful!
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 4
Available Candidates:
2. dhoni
1. vijay
Enter the candidate ID you want to vote for: 2
Vote added successfully!
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 1
Enter your username: priya
Warning: Password input may be echoed.
Enter your password: 123priya
Login successful!
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 4
Available Candidates:
2. dhoni
1. vijay
Enter the candidate ID you want to vote for: 2
Vote added successfully!
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 5
Vote Count:
dhoni: 3 votes
vijay: 2 votes
1. Login
2. Register
3. Add Candidate
4. Vote
5. Generate Results
6. Exit
Enter your choice: 6
BIBLIOGRAPHY
www.w3schools.com/python
www.techtarget.com
www.scribd.com
www.github.com