• We just launched and are currently in beta. Join us as we build and grow the community.

Creating a Simple Password Generator in Python

amen541

Reels Creator
A Rep
0
0
0
Rep
0
A Vouches
0
0
0
Vouches
0
Posts
56
Likes
86
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
In this tutorial we will create A Simple Password Generator Using Python. Python has a design philosophy which emphasizes code readability. Python is very easy to learn the syntax emphasizes readability and it can reduces time consuming in developing. You can use this application for getting your random password to a certain account.

So let's now do the 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

  1. from

    tkinter import

    *
  2. 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.

  1. root =

    Tk(

    )
  2. root.title

    (

    "Sourcecodester"

    )
  3. width =

    400
  4. height =

    200
  5. screen_width =

    root.winfo_screenwidth

    (

    )
  6. screen_height =

    root.winfo_screenheight

    (

    )
  7. x =

    (

    screen_width/2

    )

    - (

    width/2

    )
  8. y =

    (

    screen_height/2

    )

    - (

    height/2

    )
  9. root.geometry

    (

    "%dx%d+%d+%d"

    % (

    width,

    height,

    x,

    y)

    )

Creating the Main Function

This is the main function where the Entry generate a random character when button is cliked. To do that just simply copy the code below then paste it inside the IDLE text editor

  1. #=====================================METHODS===================================
  2. def

    Random(

    )

    :
  3. alphabet =

    "abcdefghijklmnopqrstuvwxyz"
  4. length =

    8
  5. new_password =

    ""

  6. for

    i in

    range

    (

    length)

    :
  7. next_index =

    random

    .randrange

    (

    len

    (

    alphabet)

    )
  8. new_password =

    new_password + alphabet[

    next_index]


  9. for

    i in

    range

    (

    random

    .randrange

    (

    1

    ,

    3

    )

    )

    :
  10. replace_index =

    random

    .randrange

    (

    len

    (

    new_password)

    //2

    )
  11. new_password =

    new_password[

    0

    :replace_index]

    + str

    (

    random

    .randrange

    (

    10

    )

    )

    + new_password[

    replace_index+1

    :]


  12. for

    i in

    range

    (

    random

    .randrange

    (

    1

    ,

    3

    )

    )

    :
  13. replace_index =

    random

    .randrange

    (

    len

    (

    new_password)

    //2

    ,

    len

    (

    new_password)

    )
  14. new_password =

    new_password[

    0

    :replace_index]

    + new_password[

    replace_index]

    .upper

    (

    )

    + new_password[

    replace_index+1

    :]

  15. PASSWORD.set

    (

    new_password)

    ;

Designing the Layout

After creating the Main Frame we will now add some layout to the application. Just kindly copy the code below and paste it inside the IDLE text editor.

  1. #====================================VARIABLES==================================
  2. PASSWORD =

    StringVar(

    )

  3. #====================================FRAME======================================
  4. Top =

    Frame(

    root,

    width=

    width)
  5. Top.pack

    (

    side=

    TOP)
  6. Form =

    Frame(

    root,

    width=

    width)
  7. Form.pack

    (

    side=

    TOP)

  8. #====================================LABEL WIDGET===============================
  9. lbl_title =

    Label(

    Top,

    width=

    width,

    font=

    (

    'arial'

    ,

    16

    )

    ,

    text=

    "Python:Password Generator"

    ,

    bd=

    1

    ,

    relief=

    SOLID)
  10. lbl_title.pack

    (

    fill=

    X)
  11. lbl_password =

    Label(

    Form,

    font=

    (

    'arial'

    ,

    18

    )

    ,

    text=

    "Password"

    ,

    bd=

    10

    )
  12. lbl_password.grid

    (

    row=

    0

    ,

    pady=

    15

    )

  13. #====================================ENTRY WIDGET===============================
  14. password =

    Entry(

    Form,

    textvariable=

    PASSWORD,

    font=

    (

    18

    )

    ,

    width=

    16

    )
  15. password.grid

    (

    row=

    0

    ,

    column=

    1

    )

  16. #====================================BUTTON WIDGET==============================
  17. btn_generate =

    Button(

    Form,

    text=

    "Generate"

    ,

    width=

    20

    ,

    command=

    Random)
  18. btn_generate.grid

    (

    row=

    1

    ,

    columnspan=

    2

    )

Demo

There you have it! We have created a Simple Password Generator 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!!

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

449,708

322,558

322,567

Top