0% found this document useful (0 votes)
13 views

Mysql

Uploaded by

srivarshinir05
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Mysql

Uploaded by

srivarshinir05
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

import mysql.

connector as sql

import datetime

# Database Connection

mycon = sql.connect(host="localhost", user="root", password="vvs", database="hubnet")

mycur = mycon.cursor()

# List of special characters for password validation

SpecialSym = ['$', '@', '#', '%', '*', '&']

def signup():

print("\nSign Up:")

while True:

try:

name = input("Enter Your Name: ")

if any(char in SpecialSym for char in name):

raise ValueError("Special characters are not allowed in the name.")

break

except ValueError as e:

print(e)

while True:

try:

username = input("Enter Your Username: ")

if any(char in SpecialSym for char in username):

raise ValueError("Special characters are not allowed in the username.")

break

except ValueError as e:

print(e)

while True:
try:

password = input("Enter Your Password: ")

if len(password) < 6:

raise ValueError("Password must be at least 6 characters long.")

if not any(char.isdigit() for char in password):

raise ValueError("Password must contain at least one number.")

if not any(char.isupper() for char in password):

raise ValueError("Password must contain at least one uppercase letter.")

if not any(char.islower() for char in password):

raise ValueError("Password must contain at least one lowercase letter.")

if not any(char in SpecialSym for char in password):

raise ValueError("Password must contain at least one special character.")

break

except ValueError as e:

print(e)

while True:

try:

dob = input("Enter Your Date of Birth (DD/MM/YYYY): ")

dob = datetime.datetime.strptime(dob, "%d/%m/%Y").date()

break

except ValueError:

print("Invalid date format. Please use DD/MM/YYYY.")

address = input("Enter Your Address: ")

while True:

try:

phone = input("Enter Your Phone Number: ")

if len(phone) != 10 or not phone.isdigit():

raise ValueError("Phone number must be 10 digits.")


break

except ValueError as e:

print(e)

while True:

try:

aadhar = input("Enter Your 12-digit Aadhar Number: ")

if len(aadhar) != 12 or not aadhar.isdigit():

raise ValueError("Aadhar number must be 12 digits.")

break

except ValueError as e:

print(e)

while True:

try:

balance = int(input("Enter the amount you want to deposit: "))

if balance < 0:

raise ValueError("Balance cannot be negative.")

break

except ValueError:

print("Please enter a valid amount.")

# Insert data into the database

query = """

INSERT INTO bank (Name, UserName, Password, DOB, Address, Phone, Aadhar, Balance)

VALUES (%s, %s, %s, %s, %s, %s, %s, %s)

"""

values = (name, username, password, dob, address, phone, aadhar, balance)

try:

mycur.execute(query, values)

mycon.commit()
print("Account created successfully! Please log in.")

except sql.Error as e:

print("Error:", e)

def signin():

print("\nSign In:")

username = input("Enter Your Username: ")

password = input("Enter Your Password: ")

query = "SELECT * FROM bank WHERE UserName = %s AND Password = %s"

mycur.execute(query, (username, password))

user = mycur.fetchone()

if user:

print(f"\nWelcome back, {user[0]}!")

# Further menu options can be implemented here

else:

print("Invalid credentials. Please try again.")

# Main Program Loop

while True:

print("\n" + "=" * 70)

print("Welcome to Colony Bank of India")

print("=" * 70)

print("1. Sign Up")

print("2. Sign In")

print("3. Exit")

try:

choice = int(input("Enter your choice: "))

if choice == 1:

signup()
elif choice == 2:

signin()

elif choice == 3:

print("Thank you for using Colony Bank of India. Goodbye!")

break

else:

print("Invalid choice. Please try again.")

except ValueError:

print("Please enter a valid number.")

You might also like