![Python Python](/uploads/1/2/5/4/125461760/631180182.jpg)
Activity Checklist. First, ask the user to input a password length, and store it in a variable called length. Use int() to turn the user’s input into a whole number. Use your length variable to repeat as many times as the user entered. Test your code. The password created should be the length entered by the user.
Write a password generator in Python. Be creative with how you generate passwords - strong passwords have a mix of lowercase letters, uppercase letters, numbers, and symbols. The passwords should be random, generating a new password every time the user asks for a new password. Include your code in a main method. Extra:. Ask the user how strong they want their password to be.
For weak passwords, pick a word or two from a list. Sample solution There are so many possible solutions to this exercise, really depending on how far you want to challenge yourself. The field of security, especially as it relates to computing, is an ever-growing field with countless experts, theories, principles, and more. The sample solution here is one possible way to answer the question: it generates a string of random characters. It is clean, simple, and elegant.
And here is another, using internal Python functions.
Simple Password Generator 5 SEP 2016. 6 mins read As a part of my weekly coding challenges I decided to create simple password generating program that allows an user to create strong and unique passwords depending on the wanted legth. It's great way to improve your programming skills and problem solving. Let's see how it works! Code I will break down the code of the program into smaller pieces that will let you step by step understand how it works.
We're going to use 2 built in libraries - random to create as random passwords as it's possible and string to let us work on the characters used in password. Import random import string Main Function Firstly, the main function should ask the user for the length of the password he wants to create - no one will use a program that will only generate passwords made of 10 characters. But we should also remember that the user input should be checked whether or not it's a digit since we don't want the password of length 't'. Def main : print ( '. Welcome to Password Generator' ) print ( '.
Remember that strong password should be longer than 8 characters!' ) length = input ( '. Enter how long would you like your password to be: ' ) if length. Isdigit : length = int ( length ) else: print ( '. Please enter a number!' ) return But what next?
As our program generates only strong passwords made of lowercase and uppercase letters, symbols and numbers and then checks for at least one of each we should consider the minimum length of the password. Any password shorter or equal to 3 character will never be generated, and we don't want to make the user sit in front of the screen for hours and hours just to generate short password. If length 0 and upper 0 and digit 0 and special 0: return True else: return False That's why I love python, even without knowing programming any person could interpret the code.
It sums the number of each parameter by checking if it's in the certain set, letter by letter. If it occurs, it will add to the sum 1, if not the sum will stay the same. Then it checks if the password contains at least one of each character type, resulting in True if the password is strong and False if it's not strong one. At the end I added the: if name 'main': main By doing the main check, you can have that code only execute when you want to run the module as a program and not have it execute when someone just wants to import your module and call your functions themselves. Check out whole code at my Github account.
I hope you enjoyed exploring the concept behind this small program. Remember that doing a lot of small challenges like that one will help you a lot in learning programming. Good luck with creating your own versions!