Python - Create User Password
Submitted by razormist on Friday, November 8, 2019 - 15:55.
In this tutorial we will create a Create User Password using Python. This code will generate a random default password for user when the generate button is clicked. The code use tkinter module to create a layout and widgets that can call python functions. When a function is called it the application will automatically generate a random character by undergoing in a for loop base on the given length. This a free useful program, feel fee to modify it and use it on your working projects.
We will be using Python because it has a design philosophy which emphasizes code readability. That's why python is very easy to use especially for beginners who just started programming. It is very easy to learn the syntax emphasizes readability and it can reduces time consuming in developing..
There you have it we just created a Create User Password using Python. I hope that this simple tutorial help you for what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!
Getting started:
First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.Importing Modules
After setting up the installation and the database, run the IDLE and click file and then new file. After that a new window will appear containing a black file this will be the text editor for the python. Then copy code that I provided below and paste it inside the IDLE text editor.- from tkinter import *
- import random
Setting up the Main Frame
After importing the modules, we will now then create the main frame for the application. To do that just copy the code below and paste it inside the IDLE text editor.- #====================================VARIABLES==================================
- PASSWORD = StringVar()
- #====================================FRAME======================================
- Top = Frame(root, width=width)
- Top.pack(side=TOP)
- Form = Frame(root, width=width)
- Form.pack(side=TOP)
- #====================================LABEL WIDGET===============================
- lbl_title = Label(Top, width=width, font=('arial', 16), text="Python - Create User Password", bd=1, relief=SOLID)
- lbl_title.pack(fill=X)
- lbl_user = Label(Form, font=('arial', 14), text="Generating User Password", bd=10)
- lbl_user.grid(row=0, columnspan=2)
- lbl_password = Label(Form, font=('arial', 18), text="Password", bd=10)
- lbl_password.grid(row=1)
- #====================================ENTRY WIDGET===============================
- password = Entry(Form, textvariable=PASSWORD, font=(18), width=16)
- password.grid(row=1, column=1)
- password.config(state='readonly')
- #====================================BUTTON WIDGET==============================
- btn_generate = Button(Form, text="Generate", width=20, command=Generate)
- btn_generate.grid(row=2, columnspan=2)
Creating the Main Function
This is where the code that contains the main functions. This code will generate random user password when the button is clicked. To do that just copy and write these blocks of code.- #=====================================METHODS===================================
- def Generate():
- chars = "abcdefghijklmnopqrstuvwxyz"
- length = 12
- password = ""
- for i in range(length):
- next_index = random.randrange(len(chars))
- password = password + chars[next_index]
- for i in range(random.randrange(1,6)):
- replace_index = random.randrange(len(password)//2)
- password = password[0:replace_index] + str(random.randrange(10)) + password[replace_index+1:]
- for i in range(random.randrange(1,6)):
- replace_index = random.randrange(len(password)//2,len(password))
- password = password[0:replace_index] + password[replace_index].upper() + password[replace_index+1:]
- PASSWORD.set(password);
Add new comment
- 617 views