Create a password generator using under 20 lines of code
June 08, 2019
- Text editor
Time to roll
- Fire up your editor of choice.
- Create a file with a .py extension
- Enter the following code in your blank file. I’m currently using Ubuntu, so you can safely omit the first line if you are using Windows.
- We start by importing the random module, which implements the choice method.
- Next we create a string of characters, inclusive of symbols. These will be chosen randomly in order to come up with a password.
- passGen is a function that takes one parameter (pass_len), which determines the length of our password. Function definition starts with the
- In the passGen function, we use a for loop to iterate over a range of
end=''tells Python that we do not want a newline at the end of each character.
- The main function asks the user the legth of the password they need, then passes that requirement to the