Question

In: Computer Science

Phyton Login program To start the program each day the manager must login. The main (manager)...

Phyton Login program

To start the program each day the manager must login. The main (manager) window will appear with a login, create password, and cancel button. A password must exist for the login button to be enabled. The password is created in a separate window and must be 9 characters or more, and it must have at least on digit, uppercase and lowercase letter. The program will continue to show error messages and prompt for a password until a valid password is created. The valid password will be stored in a file for validation on login.
When a valid password has been created or on subsequent program runs, the main window “Create Account” button for the manager will be disabled. When the login button is clicked, the main window will change (morph) to add a login entry box.

Create the “Account Creation / Login” interface and the functions using a class for the GUI in a separate module (file) and begin the design for user name and password file handling. The window is launched when the “Create Account” button is clicked. Use the <enter> key to obtain the user entry.
Design and develop the functionality for changing the window or creating a new one to obtain a user name and password including input validation. Create an error dialog that echoes the password, and create the password validation function which must test for length (9 characters or more), an uppercase and lowercase letter, and a digit. The window must contain instructions and operating “Cancel” and “Create Account” buttons.

When the “Ok” button in the “Password Accepted” dialog is clicked the Account Creation dialog should be destroyed and the main window will now have the “Create Account” button disabled. Store the user name and password for future checking. The user should login next.
Hint: The call to the login function may not be able to be handled directly through the “command=” option of the button. A call to a function within the main GUI (outside the main loop) may need to be called which then calls the login function in the separate module.

Add the code to the login function to accept the password when the <Enter> key is pressed by binding the entry widget to a function call that tests for a match with the stored password by calling a “verify” function. The entry widget should accept input left aligned in the text box. If the entered password and stored password don’t match, alert the user and the text box should be cleared like the account creation example- entry.delete(0, END). Login operations can be done on the main window as shown here or in a separate window. Consider how the user and manager would like to interface with your program.

Solutions

Expert Solution

  1. from tkinter import *

  2. import tkinter.messagebox as tkMessageBox

  3. import sqlite3

  4. root = Tk()

  5. root.title("account creaation")

  6. width = 840

  7. height = 680

  8. screen_width = root.winfo_screenwidth()

  9. screen_height = root.winfo_screenheight()

  10. x = (screen_width/2) - (width/2)

  11. y = (screen_height/2) - (height/2)

  12. root.geometry("%dx%d+%d+%d" % (width, height, x, y))

  13. root.resizable(0, 0)

  14. //variable

  15. USERNAME = StringVar()

  16. PASSWORD = StringVar()

  17. FIRSTNAME = StringVar()

  18. LASTNAME = StringVar()

  19. //db conn

  20. def Database():

  21. global conn, cursor

  22. conn = sqlite3.connect("db_member.db")

  23. cursor = conn.cursor()

  24. cursor.execute("CREATE TABLE IF NOT EXISTS `member` (mem_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, username TEXT, password TEXT, firstname TEXT, lastname TEXT)")

  25. //account creation

  26. def LoginForm():

  27. global LoginFrame, lbl_result1

  28. LoginFrame = Frame(root)

  29. LoginFrame.pack(side=TOP, pady=80)

  30. lbl_username = Label(LoginFrame, text="Username:", font=('arial', 25), bd=18)

  31. lbl_username.grid(row=1)

  32. lbl_password = Label(LoginFrame, text="Password:", font=('arial', 25), bd=18)

  33. lbl_password.grid(row=2)

  34. lbl_result1 = Label(LoginFrame, text="", font=('arial', 18))

  35. lbl_result1.grid(row=3, columnspan=2)

  36. username = Entry(LoginFrame, font=('arial', 20), textvariable=USERNAME, width=15)

  37. username.grid(row=1, column=1)

  38. password = Entry(LoginFrame, font=('arial', 20), textvariable=PASSWORD, width=15, show="*")

  39. password.grid(row=2, column=1)

  40. btn_login = Button(LoginFrame, text="Login", font=('arial', 18), width=35, command=Login)

  41. btn_login.grid(row=4, columnspan=2, pady=20)

  42. lbl_register = Label(LoginFrame, text="Register", fg="Blue", font=('arial', 12))

  43. lbl_register.grid(row=0, sticky=W)

  44. lbl_register.bind('<Button-1>', ToggleToRegister)

  45. def RegisterForm():

  46. global RegisterFrame, lbl_result2

  47. RegisterFrame = Frame(root)

  48. RegisterFrame.pack(side=TOP, pady=40)

  49. lbl_username = Label(RegisterFrame, text="Username:", font=('arial', 18), bd=18)

  50. lbl_username.grid(row=1)

  51. lbl_password = Label(RegisterFrame, text="Password:", font=('arial', 18), bd=18)

  52. lbl_password.grid(row=2)

  53. lbl_firstname = Label(RegisterFrame, text="Firstname:", font=('arial', 18), bd=18)

  54. lbl_firstname.grid(row=3)

  55. lbl_lastname = Label(RegisterFrame, text="Lastname:", font=('arial', 18), bd=18)

  56. lbl_lastname.grid(row=4)

  57. lbl_result2 = Label(RegisterFrame, text="", font=('arial', 18))

  58. lbl_result2.grid(row=5, columnspan=2)

  59. username = Entry(RegisterFrame, font=('arial', 20), textvariable=USERNAME, width=15)

  60. username.grid(row=1, column=1)

  61. password = Entry(RegisterFrame, font=('arial', 20), textvariable=PASSWORD, width=15, show="*")

  62. password.grid(row=2, column=1)

  63. firstname = Entry(RegisterFrame, font=('arial', 20), textvariable=FIRSTNAME, width=15)

  64. firstname.grid(row=3, column=1)

  65. lastname = Entry(RegisterFrame, font=('arial', 20), textvariable=LASTNAME, width=15)

  66. lastname.grid(row=4, column=1)

  67. btn_login = Button(RegisterFrame, text="Register", font=('arial', 18), width=35, command=Register)

  68. btn_login.grid(row=6, columnspan=2, pady=20)

  69. lbl_login = Label(RegisterFrame, text="Login", fg="Blue", font=('arial', 12))

  70. lbl_login.grid(row=0, sticky=W)

  71. lbl_login.bind('<Button-1>', ToggleToLogin)

  72. #========================================MENUBAR WIDGETS==================================

  73. menubar = Menu(root)

  74. filemenu = Menu(menubar, tearoff=0)

  75. filemenu.add_command(label="Exit", command=Exit)

  76. menubar.add_cascade(label="File", menu=filemenu)

  77. root.config(menu=menubar)

  78. // functions

  79. def Exit():

  80. result = tkMessageBox.askquestion('System', 'Are you sure you want to exit?', icon="warning")

  81. if result == 'yes':

  82. root.destroy()

  83. exit()

  84. def ToggleToLogin(event=None):

  85. RegisterFrame.destroy()

  86. LoginForm()

  87. def ToggleToRegister(event=None):

  88. LoginFrame.destroy()

  89. RegisterForm()

  90. def Register():

  91. Database()

  92. if USERNAME.get == "" or PASSWORD.get() == "" or FIRSTNAME.get() == "" or LASTNAME.get == "":

  93. lbl_result2.config(text="Please complete the required field!", fg="orange")

  94. else:

  95. cursor.execute("SELECT * FROM `member` WHERE `username` = ?", (USERNAME.get(),))

  96. if cursor.fetchone() is not None:

  97. lbl_result2.config(text="Username is already taken", fg="red")

  98. else:

  99. cursor.execute("INSERT INTO `member` (username, password, firstname, lastname) VALUES(?, ?, ?, ?)", (str(USERNAME.get()), str(PASSWORD.get()), str(FIRSTNAME.get()), str(LASTNAME.get())))

  100. conn.commit()

  101. USERNAME.set("")

  102. PASSWORD.set("")

  103. FIRSTNAME.set("")

  104. LASTNAME.set("")

  105. lbl_result2.config(text="Successfully Created!", fg="black")

  106. cursor.close()

  107. conn.close()

  108. def Login():

  109. Database()

  110. if USERNAME.get == "" or PASSWORD.get() == "":

  111. lbl_result1.config(text="Please complete the required field!", fg="orange")

  112. else:

  113. cursor.execute("SELECT * FROM `member` WHERE `username` = ? and `password` = ?", (USERNAME.get(), PASSWORD.get()))

  114. if cursor.fetchone() is not None:

  115. lbl_result1.config(text="You Successfully Login", fg="blue")

  116. else:

  117. lbl_result1.config(text="Invalid Username or password", fg="red")

  118. LoginForm()


Related Solutions

Create a C # program that calculates what a worker must be paid if each day...
Create a C # program that calculates what a worker must be paid if each day I work different hours during the week. The price per hour is 80.0.
Please use Phyton to write a program: Write a program that calculates and displays the total...
Please use Phyton to write a program: Write a program that calculates and displays the total bill at a restaurant for a couple that is dining. The program should collect from the couple, cost of each meal, and the percentage of the final cost that they would like to tip. The sales tax in the state where the restaurant exists is 7.5%. Display to the user, line by line: Total Cost of Both Meals Sales Tax in dollars Tip in...
create a program that will verify a user's login credentials. The program should prompt the user...
create a program that will verify a user's login credentials. The program should prompt the user to enter his/her username and password at the keyboard. Then it should read the data from a data file named "login.txt". The file "login.txt" will contain a list of 3 valid usernames and passwords to verify the login information supplied by a user.  If the username and password entered by the user matches one of the sets read from the file, the program should print...
This Program is Written in PHYTON In geomrety, the value of π can be estimated from...
This Program is Written in PHYTON In geomrety, the value of π can be estimated from an infinite series of the form: π / 4 = 1 - (1/3) + (1/5) - (1/7) + (1/9) - (1/11) + ... However, there is another novel approach to calculate π. Imagine that you have a dartboard that is 2 units square. It inscribes a circle of unit radius. The center of the circle coincides with the center of the square. Now imagine...
This Program is Written in PHYTON In geomrety, the value of π can be estimated from...
This Program is Written in PHYTON In geomrety, the value of π can be estimated from an infinite series of the form: π / 4 = 1 - (1/3) + (1/5) - (1/7) + (1/9) - (1/11) + ... However, there is another novel approach to calculate π. Imagine that you have a dartboard that is 2 units square. It inscribes a circle of unit radius. The center of the circle coincides with the center of the square. Now imagine...
This program must have 9 functions: •main() Controls the flow of the program (calls the other...
This program must have 9 functions: •main() Controls the flow of the program (calls the other modules) •userInput() Asks the user to enter two numbers •add() Accepts two numbers, returns the sum •subtract() Accepts two numbers, returns the difference of the first number minus the second number •multiply() Accepts two numbers, returns the product •divide() Accepts two numbers, returns the quotient of the first number divided by the second number •modulo() Accepts two numbers, returns the modulo of the first...
C++ : Write a program that creates a login name for a user, given the user's...
C++ : Write a program that creates a login name for a user, given the user's first name, last name, and a four-digit integer as input. Output the login name, which is made up of the first five letters of the last name, followed by the first letter of the first name, and then the last two digits of the number (use the % operator). If the last name has less than five letters, then use all letters of the...
Write a class called CheckUserName. CheckUserName must have a main method. Your program must ask for...
Write a class called CheckUserName. CheckUserName must have a main method. Your program must ask for a user name. If the name is on the list below (Liam, for example) greet the user saying: welcome back: Liam If the user is an admin (like Benkamin, for example) print: welcome back: Benjamin you have admin privileges Your program must accept upper case or lower case: emacs% java CheckUserName enter a user name: Liam welcome back: Liam emacs% java CheckUserName enter a...
Write a class called WhereIsMyNumber. WhereIsMyNumber must have a main method. Your program must ask for...
Write a class called WhereIsMyNumber. WhereIsMyNumber must have a main method. Your program must ask for a number (it must work if user enters numbers with decimal point of not). Then your program must print number is negative -- if humber is negative number in [0,10) -- if it is between 0 and 10, not including the 10 number in [10,100) -- if it is between 10 and 100, not including the 100 number in [100,1000) -- if it is...
Write a class called CheckUserName. CheckUserName must have a main method. Your program must ask for...
Write a class called CheckUserName. CheckUserName must have a main method. Your program must ask for a user name. If the name is on the list below (Liam, for example) greet the user saying: welcome back: Liam If the user is an admin (like Benkamin, for example) print: welcome back: Benjamin you have admin privileges Your program must accept upper case or lower case: emacs% java CheckUserName enter a user name: Liam welcome back: Liam emacs% java CheckUserName enter a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT