Skip to content

CS50's Introduction to Programming with Python Final Project - random username/password CLI generator

Notifications You must be signed in to change notification settings

g-k-coder/CS50P-Final-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Random Password/Username Generator

Contents

Demo: YouTube

Requirements

Instructions are for Debian-Ubuntu Operating Systems.

A step-by-step guide to install the required pip packages and others.

Open your terminal and follow the instructions

First, install or update Python 3, Git and this repository:

# Updates packages information from all configured sources
$ sudo apt update

# Installs Python3, if it is not already installed, otherwise it just updates it
$ sudo apt-get install python3 python3-dev

# Installs Git
$ sudo apt-get install git, if it is not already installed, otherwise it just updates it

# Clones the GitHub repository to your machine
$ git clone https://github.com/g-k-coder/dummy-name-not-yet-on-the-github.git

Secondly, install pip » $ sudo apt-get install python3-pip

Lastly, install packages from requirements.txt:

  • manually install each package
# Downloads and installs SOME PACKAGE
$ pip install SOME PACKAGE==SOME VERSION

# Downloads and installs argparse
$ pip install argparse==1.4.0


# Downloads and installs mypy
$ pip install mypy==1.3.0

# Downloads and installs pytest
$ pip install pytest==7.3.1

# Downloads and installs datetime
$ pip install datetime==5.1

# Downloads and installs colorama
$ pip install colorama==0.4.6

# Downloads and install black
$ pip install black==23.3.0
# Navigate to the project's directory
$ cd /path/to/project

# Installs all packages from requirements.txt
$ pip install -r requirements.txt

Modules

  • argparse - makes it easy to write user-friendly command-line interfaces. The program defines what arguments it requires, and argparse will figure out how to parse those out of sys.argv. The argparse module also automatically generates help and usage messages. The module will also issue errors when users give the program invalid arguments. source: docs.python.org

  • mypy - a static type checker for Python. Type checkers help ensure that you’re using variables and functions in your code correctly. With mypy, add type hints (PEP 484) to your Python programs, and mypy will warn you when you use those types incorrectly. source: mypy.readthedocs.io

  • pytest - framework makes it easy to write small, readable tests, and can scale to support complex functional testing for applications and libraries. source: docs.pytest.org

  • datetime - module supplies classes for manipulating dates and times. source: docs.python.org

  • colorama - simple cross-platform colored terminal text in Python. source: super-devops.readthedocs.io

  • black - the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters. source: docs.python.org

Documentation generated by pydoc for project.py

Help on module project:

NAME
    project

CLASSES
    builtins.object
        Secure
            Password
            Username

    class Password(Secure)
     |  Password(uppercase: str, lowercase: str, numbers: int, length: int = 12, symbols='*-/$%@_', punctuation='?!.:', check=False, check_special=False, **kwargs)
     |
     |  Method resolution order:
     |      Password
     |      Secure
     |      builtins.object
     |
     |  Methods defined here:
     |
     |  __init__(self, uppercase: str, lowercase: str, numbers: int, length: int = 12, symbols='*-/$%@_', punctuation='?!.:', check=False, check_special=False, **kwargs)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  __str__(self)
     |      Return str(self).
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |
     |  password
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from Secure:
     |
     |  __dict__
     |      dictionary for instance variables (if defined)
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  lowercase
     |
     |  numbers
     |
     |  uppercase

    class Secure(builtins.object)
     |  Secure(uppercase: str, lowercase: str, numbers: int, **kwargs)
     |
     |  Methods defined here:
     |
     |  __init__(self, uppercase: str, lowercase: str, numbers: int, **kwargs)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |
     |  __dict__
     |      dictionary for instance variables (if defined)
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  lowercase
     |
     |  numbers
     |
     |  uppercase

    class Username(Secure)
     |  Username(uppercase: str, lowercase: str, numbers: int, underscore: str = '_', check=False, **kwargs)
     |
     |  Method resolution order:
     |      Username
     |      Secure
     |      builtins.object
     |
     |  Methods defined here:
     |
     |  __init__(self, uppercase: str, lowercase: str, numbers: int, underscore: str = '_', check=False, **kwargs)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  __str__(self)
     |      Return str(self).
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |
     |  username
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from Secure:
     |
     |  __dict__
     |      dictionary for instance variables (if defined)
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  lowercase
     |
     |  numbers
     |
     |  uppercase

FUNCTIONS
    generate_password(uppercase: str, lowercase: str, numbers: int, amount: int, **kwargs) -> bool
        Generate passwords and print them

        :param uppercase: letters to be converted to uppercase
        :type: str

        :param lowercase: letters to be converted to lowercase
        :type: str

        :param numbers: numbers to implement in username
        :type: int

        :param amount: amount of samples to create and print
        :type: int

        :return: Indicate success
        :rtype: bool

    generate_shuffle(pattern: str) -> bool
        Shuffle text and print it

        :param pattern: text to shuffle
        :type: str

        :return: Indicate success
        :rtype: bool

    generate_username(uppercase: str, lowercase: str, numbers: int, amount: int, **kwargs) -> bool
        Generate usernames and print them

        :param uppercase: letters to be converted to uppercase
        :type: str

        :param lowercase: letters to be converted to lowercase
        :type: str

        :param numbers: numbers to implement in username
        :type: int

        :param amount: amount of samples to create and print
        :type: int

        :return: Indicate success
        :rtype: bool

    main()

DATA
    Fore = <colorama.ansi.AnsiFore object>

FILE
    /python-final/cs50p/project.py

Documentation generated by pydoc for test_project.py

Help on module test_project:

NAME
    test_project

FUNCTIONS
    test_Password()
        Test the class generating passwords

    test_Secure()
        Test the superclass of both Username and Password

    test_Secure_lowercase()
        Test lowercase getter and setter

    test_Secure_numbers()
        Test numbers getter and setter

    test_Secure_uppercase()
        Test uppercase getter and setter

    test_Username()
        Test the class generating usernames

    test_generate_password()
        Test the function that prompts the user to
        specify wether they want special characters and/or punctuation in password or not,
        which then tries to instantiate the Password class,
        and returns True on success

    test_generate_shuffle()
        Test the function shuffling the string provided by the user

    test_generate_username()
        Test the function that prompts the user to
        specify wether they want underscore in username or not,
        which then tries to instantiate the Username class,
        and returns True on success

FILE
    /python-final/cs50p/test_project.py

Testing - PEP 484

Open your terminal and navigate to the project's directory:

# Navigate to the project's directory
$ cd /path/to/project

# Runs all tests for all classes, methods and functions
$ pytest test_project.py


# Output should resemble the following
==================== test session starts ====================
platform linux -- Python 3.10.6, pytest-7.3.1, pluggy-1.0.0
rootdir: /python-final/cs50p
collected 9 items

test_project.py .........                                                                                                                 [100%]

===================== 9 passed in 0.02s ======================

Design and style - PEP 8

# Navigate to the project's directory
$ cd /path/to/project

# Modifies the code to match the conventions
$ black project.py


# Output should resemble the following
All done! ✨ 🍰 ✨
1 file left unchanged.

Help

# Navigate to the project's directory
$ cd /path/to/project

# Modifies the code to match the conventions
$ python3 project.py -h


# Output should resemble the following
usage: project.py [-h] -m {username,password,shuffle} [-a AMOUNT] [-t TEXT]

Generate random username and password

options:
  -h, --help            show this help message and exit
  -m {username,password,shuffle}, --mode {username,password,shuffle}
                        choose between the modes of username and password
  -a AMOUNT, --amount AMOUNT
                        amount of output samples to generate
  -t TEXT, --text TEXT  string to shuffle


About

CS50's Introduction to Programming with Python Final Project - random username/password CLI generator

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages