top of page
Subham Das

This coding is with GUI interaction in Python unlike the last code. Here we are working with a login system where all the data is automatically stored in our database MySQL. For using MySQL we are using an external module named 'mysql.connector'. You can also use sqlite3 instead MySQL. One part of the code also deals with Exceptional Handling. Actually I am creating a database using different Exceptions. You can also manually create your database but I considered about the worst case possible that is the reason of using Exceptional Handling. It will create a database name 'login' and a table name 'main' inside the database if it doesn't exist. This is the benefit of my code.






# Login System with Python GUI and MySQL


import mysql.connector as sql

from tkinter import *


win = Tk()

win.geometry("500x500")

win.title("Login Page")


def login() :

db = sql.connect(host = "localhost", user = "root", passwd = "")

cur = db.cursor()


try :

cur.execute("create database login")

db = sql.connect(host = "localhost", user = "root", passwd = "", database = "login")

cur = db.cursor()


except sql.errors.DatabaseError:

db = sql.connect(host = "localhost", user = "root", passwd = "", database = "login")

cur = db.cursor()


try :

cur.execute("create table main(username varchar(50), NOT NULL, password int NOT NULL)")


except sql.errors.ProgrammingError:

pass


finally :

try :

cur.execute("create table main(username varchar(50) NOT NULL, "

"password int NOT NULL)")


except sql.errors.ProgrammingError:

pass


while True :


user = user1.get()

passwd = passwd1.get()


cur.execute("select * from main where username = '%s' and password = %s" % (user, passwd))

rud = cur.fetchall()


if rud:

print("Welcome")

break


else:

cur.execute("insert into main values('{}', {})".format(str(user), passwd))

db.commit()

print("Account Created")

break


cur.close()

db.close()

userlvl = Label(win, text = "Username :")

passwdlvl = Label(win, text = "Password :")


user1 = Entry(win, textvariable = StringVar())

passwd1 = Entry(win, textvariable = IntVar().set(""))


enter = Button(win, text = "Enter", command = lambda: login(), bd = 0)

enter.configure(bg = "pink")


user1.place(x = 200, y = 220)

passwd1.place(x = 200, y = 270)


userlvl.place(x = 130, y = 220)

passwdlvl.place(x = 130, y = 270)


enter.place(x = 238, y = 325)


win.mainloop()


4,683 views0 comments
Subham Das

It is a composite number whose sum of the digits is 10. If we extract the digits from the number then the sum of these digits will be 10. Are confused with the statement 'math.log(i, 10) + 1' ? This is nothing but a algorithm which will give us the number of digits in a number.


# Special Magic Composite Number whose sum is 10


import math


def prime(n) :

for i in range(2,n) :

if n%i == 0 :

return True

else :

return False


for i in range(1,100) :

c = prime(i)

if c == True :

quo = i

s = 0

d = int(math.log(i, 10)) + 1

for j in range(0,d) :

rem = quo % 10

quo = quo // 10

s = s + rem

if s == 10 :

print(i)


24 views0 comments
Subham Das

Here we are working with a login system where all the data is automatically stored in our database MySQL. For using MySQL we are using an external module named 'mysql.connector'. You can also use sqlite3 instead MySQL. One part of the code also deals with Exceptional Handling. Actually I am creating a database using different Exceptions. You can also manually create your database but I considered about the worst case possible that is the reason of using Exceptional Handling. It will create a database name 'login' and a table name 'main' inside the database if it doesn't exist. This is the benefit of my code.


# Login System using Python and MySQL


import mysql.connector as sql


def login() :


db = sql.connect(host = "localhost", user = "root", passwd = "")

cur = db.cursor()


try :

cur.execute("create database login")

db = sql.connect(host = "localhost", user = "root", passwd = "", database = "login")

cur = db.cursor()


except sql.errors.DatabaseError :

db = sql.connect(host = "localhost", user = "root", passwd = "", database = "login")

cur = db.cursor()


try :

cur.execute("create table main(username varchar(50), NOT NULL, password int NOT NULL)")

except sql.errors.ProgrammingError :

pass


finally :

try :

cur.execute("create table main(username varchar(50) NOT NULL, password int NOT NULL)")

except sql.errors.ProgrammingError :

pass


while True :


flag = 0

user = input("Enter Username :")

passwd = int(input("Enter Password :"))


cur.execute("select * from main where username = '%s' and password = %s" % (user, passwd))

rud = cur.fetchall()


if rud :

print("Welcome")

flag = 1

if flag == 1 :

break


else :

cur.execute("insert into main values('{}', {})". format(str(user), passwd))

db.commit()

print("Account Created")

flag = 1

if flag == 1 :

break


cur.close()

db.close()


login()


1,752 views0 comments
logo12.PNG
bottom of page