You are on page 1of 12

Assignment Title: Password Generator

Coursework Type: Individual

Module Name:
ST4061CEM Programming and Algorithms

Submitted By: Submitted To:


CU ID:14805851 Name: Suman
Shrestha
College ID: 230518
Name: Dipesh Dhakal
Acknowledgement
I would like to express my heartfelt gratitude to their module teacher, Mr. Suman Shrestha, for
giving his valuable time and providing helpful advice. They also acknowledge his contribution to
improving the quality and accuracy of my report, as well as his guidance in honing their research
and problem-solving abilities. They also thank Softwarica College and Coventry University for
providing them with this fantastic opportunity, highlighting how the experience gained from this
project has been invaluable for their personal and academic development.

2 | 14805851
Abstract
Password security is paramount in safeguarding online accounts against unauthorized access,
necessitating the use of strong and randomized passwords. Python-based password generators
offer a versatile solution by leveraging the language's built-in modules and functionalities. This
paper explores the fundamentals of password generation using Python, highlighting key concepts
such as string manipulation, randomization techniques, and user input validation. The script
outlined demonstrates how to create robust passwords within user-defined parameters, ensuring
both security and usability. Despite challenges such as entropy and usability concerns, future
enhancements hold promise for improving password generation techniques. By addressing these
challenges, Python-based password generators can continue to evolve, offering enhanced
effectiveness and contributing to a safer online environment.

3 | 14805851
Contents
Acknowledgement............................................................................................................................2
Abstract.............................................................................................................................................3
Introduction......................................................................................................................................5
What is a Password Generator?........................................................................................................5
Literature review..............................................................................................................................6
Key Concepts....................................................................................................................................6
Code Structure..................................................................................................................................7
Code explanation.............................................................................................................................8
Algorithm.........................................................................................................................................9
Challenges and Future Directions:.................................................................................................10
Future Enhancement.......................................................................................................................10
Conclusion......................................................................................................................................11
Reference........................................................................................................................................11

4 | 14805851
Introduction
This Python script is designed to generate a random password according to user-defined
specifications. It begins by asking the user to input their desired password length, ensuring it falls
within the range of 4 to 20 characters, thereby accommodating both security and usability
considerations. Once the user provides the desired length, the script proceeds to create a password
by combining various character types. These character types include lowercase letters, uppercase
letters, digits, and special characters, ensuring that the generated password is diverse and robust.
To achieve this, the script leverages Python's built-in string module, which provides convenient
access to predefined constants representing different character sets. By combining these character
sets, the script ensures that the generated password contains a mix of characters, making it
resistant to common password cracking techniques.
Furthermore, the script utilizes Python's random module to shuffle the characters, enhancing the
randomness of the generated password. This randomization process adds an extra layer of
security by making it more difficult for potential attackers to predict the password.
The user is then presented with the generated password, allowing them to use it for their desired
purposes, whether it be for creating a new online account or updating an existing password.
Overall, this Python script provides a simple yet effective solution for generating strong and
random passwords. By allowing users to specify the desired length and incorporating a mix of
character types, it ensures that the generated passwords are both secure and user-friendly.
Additionally, the script's reliance on Python's built-in modules makes it easy to understand and
implement, even for those with limited programming experience.

What is a Password Generator?


A password generator is a program that creates random and strong passwords for various online
accounts. It eliminates the need for using predictable and easy-to-guess passwords like “123456”
or “password.”
A strong password consists of at least more than ten characters with a combination of characters
such as percent (%), commas (,), and parentheses, as well as lower-case and upper-case alphabets
and numbers.
With a password generator, you can create unique and secure passwords that are difficult for
others to guess, protecting your online accounts from unauthorized access.

5 | 14805851
Literature review
Password generators implemented in Python offer a versatile solution for creating robust
passwords tailored to individual preferences. Leveraging Python's flexibility and extensive
libraries, these generators combine various character sets to produce randomized passwords. Key
concepts in password generation using Python include:
1. String Module: The string module in Python provides a collection of string constants
representing different character sets, such as lowercase and uppercase letters, digits, and
special characters.
2. Random Module: Python's random module enables the generation of random numbers
and the shuffling of sequences, facilitating the creation of unpredictable passwords.
3. User Input: Password generators typically prompt users to input their desired password
length and may offer additional options such as including or excluding certain character
types.
4. Password Generation Logic: The generation process involves combining selected
character sets, shuffling them randomly, and extracting characters based on the specified
length to create unique passwords.

Key Concepts
1. String Module: The script imports the string module to access predefined constants
like ascii_lowercase, ascii_uppercase, digits, and punctuation.
2. Random Module: The random module is used to shuffle the characters to create a
random password.
3. User Input: The script prompts the user to enter the desired password length and validates
the input to ensure it falls within the specified range.
4. Password Generation: It combines all character sets, shuffles them, and selects
characters based on the user-defined length to create a unique password.

6 | 14805851
Code Structure
1. Import necessary modules: string and random.
2. Define character sets for lowercase letters, uppercase letters, digits, and special characters.
3. Prompt the user to enter the password length within the range of 4 to 20 characters.
4. Validate the user input to ensure it is a valid integer within the specified range.
5. Combine all character sets, shuffle them randomly.
6. Generate a password by selecting characters based on the user-defined length.
7. Display the generated password to the user.

7 | 14805851
Code explanation

Imports the string module, which contains several constant strings of ASCII characters, such as
lowercase and uppercase letters, digits, and punctuation.
Imports the random module, which provides functions for generating random numbers and
shuffling sequences.

Checks if the script is being run directly as the main program.

Assigns the constant strings containing lowercase letters, uppercase letters, digits, and
punctuation marks from the string module to variables s1, s2, s3, and s4, respectively.

Starts an infinite loop to handle user input for the password length.

Prompts the user to enter the desired length for the password as an integer.

Checks if the entered password length is within the specified range (4 to 20 characters). If not, it
prompts the user to enter a valid length. If the length is valid, it breaks out of the loop.

8 | 14805851
Handles the exception if the user enters a value that cannot be converted to an integer.

Concatenates all the strings of lowercase letters, uppercase letters, digits, and
punctuation marks and converts the result to a list.

Shuffles the list s randomly, rearranging the elements in it.

Prints a message indicating that the generated password is being displayed. Converts the first
plen elements of the shuffled list s back into a string and prints it. This string represents the
generated password.

Algorithm

1. Start by importing necessary modules: `string` and `random`.


2. Define variables `s1`, `s2`, `s3`, and `s4` to hold lowercase letters, uppercase letters, digits, and
punctuation characters respectively.
3. Start a loop that will continue indefinitely.
4. Inside the loop, ask the user to input a password length between 4 and 20 characters.
5. Check if the entered password length is within the valid range. If not, prompt the user to enter a
valid length.
6. If the input is valid, break out of the loop.
7. Combine all the characters (lowercase letters, uppercase letters, digits, and punctuation
characters) into a single list `s`.
8. Shuffle the list `s` to randomize the order of characters.
9. Print a message indicating the generated password is being displayed.

9 | 14805851
10. Print the first `plen` characters from the shuffled list `s` to generate the password.
11. End of the algorithm.

Challenges and Future Directions:


Despite their efficacy, password generators face several challenges and opportunities for future
enhancement:
1. Entropy and Randomness: Ensuring sufficient entropy and randomness in generated
passwords is crucial for security. Future research may explore advanced techniques for
improving entropy sources and enhancing randomness.
2. Biases and Patterns: Password generation algorithms must avoid biases and predictable
patterns that could compromise security. Continued refinement of algorithms to minimize
biases and increase unpredictability is essential.
3. Usability and Accessibility: Password generators should be user-friendly and accessible
to individuals with diverse needs and abilities. Enhancements in usability, such as intuitive
interfaces and support for accessibility features, can improve adoption and usability.
4. Integration and Compatibility: Integrating password generators with password
management ecosystems and ensuring compatibility across platforms and devices can
streamline password management processes and enhance user experience.
5. Security and Privacy: Protecting user data and privacy is paramount. Future
enhancements may include implementing additional security measures, such as encryption
and secure storage of generated passwords.

Future Enhancement
Future enhancements in password generation could include:
1. Advanced Entropy Sources: Exploring advanced entropy sources, such as hardware-
based random number generators or machine learning algorithms, to improve the
randomness of generated passwords.
2. Personalized Password Generation: Incorporating user behavior analysis and
preferences to generate personalized passwords that are both secure and memorable for
individual users.
3. Integration with Password Managers: Integrating password generators with password
management ecosystems to provide seamless password generation and management
capabilities within a single platform.
4. Enhanced Usability Features: Adding features such as password strength meters,
password policies, and support for biometric authentication to enhance usability and
security for users.

10 | 14805851
5. Cross-Platform Compatibility: Ensuring compatibility with various operating systems,
browsers, and devices to provide a consistent user experience across different platforms.

Conclusion
In conclusion, Python-based password generators provide a robust means for generating strong
and personalized passwords. Leveraging Python's capabilities and vast libraries, these tools
empower users to create complex passwords that meet their individual needs. Despite facing
challenges like entropy, biases, and usability issues, ongoing research and development endeavors
hold promise for refining password generators, thereby bolstering online security globally. By
addressing these challenges, future iterations of password generators can continue to evolve,
offering enhanced effectiveness and usability, and ultimately contributing to a safer online
environment for users worldwide.

GitHub link
https://github.com/R00052931D/password-generator

11 | 14805851
Reference

Shreya. (2023, July 15). Create random password generator program using Python.

Codingal. https://www.codingal.com/coding-for-kids/blog/create-random-

password-generator-program-using-python/

Follow, C. (2022, June 1). Create a Random Password Generator using Python.

GeeksforGeeks. https://www.geeksforgeeks.org/create-a-random-password-

generator-using-python/

How to create a random password generator using Python. (2022, September 3).

Hackernoon.com. https://hackernoon.com/how-to-create-a-random-password-

generator-using-python

12 | 14805851

You might also like