Simple Password Generator in Python

NeuralNine · Beginner ·💻 AI-Assisted Coding ·5y ago

Key Takeaways

The video demonstrates how to build a simple password generator in Python using the random library, string functions, and conditional statements to create a customizable password generator.

Full Transcript

[Music] what is going on guys welcome back in today's video we're going to build a simple password generator in python so let us get right into it so creating a password generator in python is a very simple thing the only thing we need to do is we need to import the random and then we're going to create a bunch of strings containing all possible characters that we can use for the password so let's say we have for example upper case letters here this is one thing and we're just going to make a string here with a b c d e f g h i j k l m n o p q r s t u v w x y z there you go then we're going to say lowercase letters and we don't need to write uh everything again we can just say uppercase letters dot lower using the string function here then we can also say numbers we're actually digits and we can say this is a string of 0 1 2 3 4 5 6 7 8 9. that's it and last but not least we can add all kinds of symbols so we're going to say symbols equals and you can include whatever you want here you can say for example i'm going to include include parentheses square brackets curly brackets uh commas semicolons colons dots uh everything you want actually underlines slash uh with backslash you need to be a little bit careful because if you do just backslash it's not going to count this as backslash you need to do backslash backslash backslash if you actually want to do uh backslash and uh then we're going to say question mark and plus and star and hashtag and i don't know what whatever you want so we're going to include all those here we can also include a white space uh and then what we're going to do is we're going to make booleans for selecting uh which things we want to include in the password that we're generating so we're going to say upper lower digits actually digits is already used so let's say nums for numbers uh and then sims for symbols okay then we're going to set all those to true in the beginning we can later on set them to false if we want uh or we can also set them to true or false uh based on the user input if you want to do that i'm just going to do it directly in the script and then we're going to uh to create a um a string for the final password so we're going to say password equals and an empty string now what we're going to do is we're going to say um or actually we're not going to do the password yet we're going to create first of all a string containing all the things that we're going to use so we're going to say if upper if it's true we're going to say creating a empty string up here we're going to say all plus equals uppercase letters which means that if we chose to use uppercase letters we're going to include them into the final string so then we're going to say if lower same thing all plus equals lowercase letters then we're going to say if digits or actually we said nums if nums all plus equals digits and then last but not least if sims all plus equal symbols so that's it we then have a final string depending on which of those indicators here are true or false we have a full string with all the things that we want to use and then last but not least what we're going to do is we're going to set the length to whatever we want it so let's say 20 and we're going to set the amount of passwords that we want to generate so let's say we want to generate 10 passwords for now and now we can get into the actual generation we've now chosen uh what kind of uh characters we want to use we've chosen the length of the password and the amount of passwords it won't generate so what we're now going to do is we're just going to go ahead and say 4 x in range length or actually amount first uh for x in range amount we're just going to say password equals and we're going to join them on an empty string here so we're going to join if you don't know what the join function does check out the python tips and tricks tutorial about the join function and what we're going to do is we're going to say random sorry random.sample which means it's just going to take anything out of the full string that we have random.sample all length which means that we're using the all string the complete string with all the things all the characters that we're using and we define the length of this string to be 20. so we're going to take 20 samples out of that string after that we can go ahead and print the password and actually we're done so that's actually everything we need to do in order to create a password generator looking down here we see that we have generated uh only five passwords why is that am i maybe running an old script here i think i'm i am there you go um this is actually the script that i uh that we have written uh right now so you can see we have 10 passwords here generated with all kinds of symbols numbers and letters we can also go ahead and say okay i'm not interested in symbols i don't want to use symbols here so we can rerun that and you can see that we don't have any symbols in the password we can set this to true again and say i don't want any letters in the password so we're going to say false and false here and there you go we'll only get numbers and symbols uh we can also of course go ahead and increase the length to 40 and create like 20 passwords here not a problem and you can see uh what do we have here sample oh yeah we cannot do uh length 40 of course because we don't have enough characters if we don't set all these to true because sample means that we cannot reuse characters so let's get this back to 40 but use everything and you can see that we have longer passwords here as well now you can also go ahead and repeat uh repeat those things by just doubling the string or something like that and one last thing that we can do here is we can also use a seat which is not very reasonable but if you want to do this uh you can use a seat a seat has the effect that you will always get the same password so in this case whenever i rerun the script i get different passwords here as you can see they're not the same however if i say my seed or actually just seed equals for example neural nine i can go ahead and say random dot seed seed and we will always get the same results so i get u o m o if i rerun this i get again u o m o and all the other passwords are the same as well so i don't know why you want to use that if you want to use that but i would not recommend it just wanted to show you that this works but that is how you build a password generator in python so that's it for this video i hope you enjoyed it i hope you learned something if so let me know by hitting the like button and leaving a comment in the comment section down below also make sure you subscribe to this channel in order to see more future videos for free and if you don't want to miss a single video click the notification bell activate it uh it should be somewhere right beside the subscribe button so if you want to make sure you don't miss out any videos go ahead and click that other than that thank you very much for watching see you in the next video and bye [Music] you

Original Description

Today we are building a simple password generator in Python. ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎵 Outro Music From: https://www.bensound.com/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from NeuralNine · NeuralNine · 0 of 60

← Previous Next →
1 Visualizing Stock Data With Candlestick Charts in Python
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
2 Python Beginner Tutorial #1 - Installation and First Program
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
3 Python Beginner Tutorial #2 - Variables and Data Types
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
4 Python Beginner Tutorial #3 - Operators and User Input
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
5 Python Beginner Tutorial #4 - If Statements and Conditions
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
6 Python Beginner Tutorial #5 - Loops
Python Beginner Tutorial #5 - Loops
NeuralNine
7 Python Beginner Tutorial #6 - Sequences and Collections
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
8 Python Beginner Tutorial #7 - Functions
Python Beginner Tutorial #7 - Functions
NeuralNine
9 Python Beginner Tutorial #8 - Exception Handling
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
10 Python Beginner Tutorial #9 - File Operations
Python Beginner Tutorial #9 - File Operations
NeuralNine
11 Python Beginner Tutorial #10 - String Functions
Python Beginner Tutorial #10 - String Functions
NeuralNine
12 Python Intermediate Tutorial #1 - Classes and Objects
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
13 Python Intermediate Tutorial #2 - Inheritance
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
14 Python Intermediate Tutorial #3 - Multithreading
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
15 Python Intermediate Tutorial #4 - Synchronizing Threads
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
16 Python Intermediate Tutorial #5 - Events and Daemon Threads
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
17 Python Intermediate Tutorial #6 - Queues
Python Intermediate Tutorial #6 - Queues
NeuralNine
18 Python Intermediate Tutorial #7 - Sockets and Network Programming
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
19 Python Intermediate Tutorial #8 - Database Programming
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
20 Python Intermediate Tutorial #9 - Recursion
Python Intermediate Tutorial #9 - Recursion
NeuralNine
21 Python Intermediate Tutorial #10 - XML Processing
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
22 Python Intermediate Tutorial #11 - Logging
Python Intermediate Tutorial #11 - Logging
NeuralNine
23 Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
24 Python Data Science Tutorial #2 - NumPy Arrays
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
25 Python Data Science Tutorial #3 - Numpy Functions
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
26 Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
27 Python Data Science Tutorial #5 - Subplots and Multiple Windows
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
28 Python Data Science Tutorial #6 - Matplotlib Styling
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
29 Python Data Science Tutorial #7 - Bar Charts with Matplotlib
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
30 Python Data Science Tutorial #8 - Pie Charts with Matplotlib
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
31 Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
32 Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
33 Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
34 Python Data Science Tutorial #12 - Pandas Series
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
35 Python Data Science Tutorial #13 - Pandas Data Frames
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
36 Python Data Science Tutorial #14 - Pandas Statistics
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
37 Python Data Science Tutorial #15 - Pandas Sorting and Functions
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
38 Python Data Science Tutorial #16 - Pandas Merging Data Frames
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
39 Python Data Science Tutorial #17 - Pandas Queries
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
40 Python Machine Learning Tutorial #1 - What is Machine Learning?
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
41 Python Machine Learning Tutorial #2 - Linear Regression
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
42 Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
43 Python Machine Learning #4 - Support Vector Machines
Python Machine Learning #4 - Support Vector Machines
NeuralNine
44 Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
45 Python Machine Learning Tutorial #6 - K-Means Clustering
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
46 Python Machine Learning Tutorial #7 - Neural Networks
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
47 Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
48 Generating Poetic Texts with Recurrent Neural Networks in Python
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
49 Stock Portfolio Visualization with Matplotlib in Python
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
50 Analyzing Coronavirus with Python (COVID-19)
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
51 Making Text Images Readable Again with Python and OpenCV
Making Text Images Readable Again with Python and OpenCV
NeuralNine
52 Neural Networks Simply Explained (Theory)
Neural Networks Simply Explained (Theory)
NeuralNine
53 Motion Filtering with OpenCV in Python
Motion Filtering with OpenCV in Python
NeuralNine
54 Top 5 Programming Languages To Learn in 2020
Top 5 Programming Languages To Learn in 2020
NeuralNine
55 Simple TCP Chat Room in Python
Simple TCP Chat Room in Python
NeuralNine
56 Image Classification with Neural Networks in Python
Image Classification with Neural Networks in Python
NeuralNine
57 Edge Detection with OpenCV in Python
Edge Detection with OpenCV in Python
NeuralNine
58 S&P 500 Web Scraping with Python
S&P 500 Web Scraping with Python
NeuralNine
59 Simple Sentiment Text Analysis in Python
Simple Sentiment Text Analysis in Python
NeuralNine
60 Introduction - Algorithms & Data Structures #1
Introduction - Algorithms & Data Structures #1
NeuralNine

This video teaches how to build a simple password generator in Python using the random library and string functions. The generator can be customized to include uppercase letters, lowercase letters, digits, and symbols, and can generate multiple passwords of a specified length.

Key Takeaways
  1. Import the random library
  2. Define strings for uppercase letters, lowercase letters, digits, and symbols
  3. Create conditional statements to customize password generation
  4. Use the random.sample function to generate passwords
  5. Print the generated passwords
💡 The random.sample function can be used to generate passwords without reusing characters, and the random.seed function can be used to generate the same passwords repeatedly.

Related Reads

Up next
Claude Can Now Do EVERYTHING on Shopify
Brendan Gillen
Watch →