Advertisement

Password Picker ( Python Project )

 Password Picker

Passwords stop other people from accessing our computers, personal emails, and website login details. In this project, you’ll build a tool that makes secure, memorable passwords to help keep your private information safe.



What happens

Password Picker will enable you to create strong passwords by combining words, numbers, and characters. When you run the program, it will create a new password and show it on the screen. You can ask it to keep creating new passwords until you find one you like.

How it works

This project will show you how to use Python’s random module. The program uses random choices from groups of adjectives, nouns, numbers, and punctuation characters to assemble each password. You’ll soon be making crazy, hard-to-forget passwords, such as “fluffyapple14(“ or “smellygoat&”!

Password Picker flowchart

The program randomly selects each of the password’s four parts, puts them together, and displays the password in the shell window. If you want another password, it repeats those steps again. If you don’t, the program ends.




1    Create a new file


Open IDLE. Under the File menu, select New File. Save the file as “password_picker.py”.


2    Add the modules


Import the string and random modules from the Python library. Type these two lines at the top of your file, so you can use the modules later.


3    Welcome the user


First create a message to welcome the user to the program.


4    Try out the code


Run your code. The welcome message should appear in the shell window.


5    Make an adjective list


You’ll need adjectives and nouns to generate new passwords. In Python, you can keep a group of related things together as a list. First create the variable adjectives to store your list by typing this new block of code between the print() command and the import statements. Put the whole list in square brackets, and separate each item with a comma.


6    Make a noun list


Next create a variable that holds a list of nouns. Put it under the adjective list and above the print() command. Remember to use commas and square brackets, like you did in Step 5.


7    Pick the words


To create the password, you’ll need to pick a random adjective and a random noun. You do this using the choice() function from the random module. Type this code below the print() command. (You can use this function any time you want to select a random item from a list. Just give it the variable containing the items.)


8    Select a number


Now use the randrange() function from the random module to select a random number from 0 to 99. Put this line at the bottom of your code.


9    Select a special character


Using the random.choice() function again, add this line to pick a random punctuation character. This will make your password even harder to crack!


10    Create the new secure password


It’s time to assemble all the different parts to create the new secure password. Type these two lines of code at the end of your program.


11    Test the program


This is a good point to test your code. Run it and look in the shell to see the result. If you have errors, don’t worry. Look back over your code carefully to spot any mistakes.


12    Another one?


You can use a while loop to generate another password if the user says they want a different one. Add this code to your program. It asks the user if they require a new password, then stores the reply in a variable called response.


13    Pick a perfect password


That’s it – you’ve finished. Now you can create hard-to-crack passwords that are fun to remember!


CODE


import random

import string

adjectives = ['sleepy', 'slow', 'smelly',

'wet', 'fat', 'red',

'orange', 'yellow', 'green',

'blue', 'purple', 'fluffy',

'white', 'proud', 'brave']

nouns = ['apple', 'dinosaur', 'ball',

'toaster', 'goat', 'dragon',

'hammer', 'duck', 'panda']


print('Welcome to Password Picker!')


while True:

    adjective = random.choice(adjectives)

    noun = random.choice(nouns)

    number = random.randrange(0, 100)

    special_char = random.choice(string.punctuation)


    password = adjective + noun + str(number) + special_char

    print('Your new password is: %s' % password)


    response = input('Would you like another password? Type y or n: ')

    if response == 'n':

break








Post a Comment

0 Comments