Password Generator

Web Application

·

7 min read

Password Generator

Hi guys good evening to all today we are going to develop a web by generating passwords

Do you notice that Google generates new passwords every time we request one?

It's such a great feature that adds an extra layer of security to our online accounts. With so many potential threats online, we must take every precaution to protect our personal information. So, the next time you need to create a new password,

a great feature that adds an extra layer of security to our online accounts. With so many potential threats online, we must take every precaution to protect our personal information. So, the next time you need to create a new password,

let's take advantage of Google's password generator feature for added peace of mind.

import streamlit as st
import random

def generatePassword(pwlength):
    alphabet = "abcdefghijklmnopqrstuvwxyzZXCVNMLKJHGFDSAPOIUYTREWQ123456789/*-+"
    passwords = []

    for length in pwlength:
        password = ""
        for _ in range(length):
            next_letter_index = random.randrange(len(alphabet))
            password += alphabet[next_letter_index]

        password = replaceWithNumber(password)
        password = replaceWithUppercaseLetter(password)

        passwords.append(password)

    return passwords

def replaceWithNumber(pword):
    for _ in range(random.randrange(1, 3)):
        replace_index = random.randrange(len(pword) // 2)
        pword = pword[:replace_index] + str(random.randrange(10)) + pword[replace_index + 1:]
    return pword

def replaceWithUppercaseLetter(pword):
    for _ in range(random.randrange(1, 3)):
        replace_index = random.randrange(len(pword) // 2, len(pword))
        pword = pword[:replace_index] + pword[replace_index].upper() + pword[replace_index + 1:]
    return pword

def main():
    st.title("Random Password Generator")

    numPasswords = st.number_input("How many passwords do you want to generate?", min_value=1, step=1, value=1)

    st.write("Generating " + str(numPasswords) + " passwords")

    passwordLengths = []
    min_length = 3
    st.write(f"Minimum length of password should be {min_length}")

    for i in range(numPasswords):
        length = st.number_input(f"Enter the length of Password #{i + 1}", min_value=min_length, step=1,
                                 value=min_length)
        passwordLengths.append(length)

    if st.button("Generate Passwords"):
        Passwords = generatePassword(passwordLengths)

        for i, password in enumerate(Passwords):
            st.write(f"Password #{i + 1}: {password}")


if __name__ == "__main__":
    main()

let's use Google's password generator feature for added peace of mind.

the above code generates a website that asks how many

Introduction: A random password generator is a useful tool for creating secure passwords with varying levels of complexity. Streamlit is a Python library that simplifies the process of creating web applications with interactive elements, making it an excellent choice for building a password generator app. In this guide, we'll walk through the steps to create a random password generator using Streamlit.

Step 1: Setup: Ensure you have Python installed on your system. You can install Streamlit via pip:

pip install streamlit

Step 2: Import Necessary Libraries: Import the required libraries, including Streamlit and random.

Step 3: Define Password Generation Functions: Create functions to generate random passwords. These functions can include logic to generate passwords with a mix of letters, numbers, and special characters.

Step 4: Create the Streamlit App: Define the main function where you'll build the Streamlit app. Set up the user interface elements such as text inputs, buttons, and sliders for user interaction.

Step 5: Generate Passwords: When the user interacts with the app (e.g., clicks a button), call the password generation functions to generate random passwords based on user input parameters.

Step 6: Display Passwords: Display the generated passwords to the user within the Streamlit app interface.

Step 7: Run the Streamlit App: Run the Streamlit app using the command:

streamlit run your_file.py
my file is main.py

Conclusion: Building a secure and user-friendly random password generator app using Streamlit is a simple process that can be accomplished with just a few lines of code. By following the steps outlined in this guide, you can create an app that allows users to easily generate strong passwords of varying complexity. With this app, you can ensure that your users' accounts are well-protected and secure.

Results:

app

website link:http://192.168.0.100:8501

1.

2

Explanation:

Sure, let's break down each line of the provided code:

pythonCopy codeimport streamlit as st
import random
  1. import streamlit as st: This imports the Streamlit library and aliases it as st for easier usage.

  2. import random: This imports the random module, which is used for generating random numbers and selecting random elements.

pythonCopy codedef generatePassword(pwlength):
    alphabet = "abcdefghijklmnopqrstuvwxyzZXCVNMLKJHGFDSAPOIUYTREWQ123456789/*-+"
    passwords = []
  1. def generatePassword(pwlength):: This line defines a function named generatePassword that takes a list pwlength as input. This list contains the lengths of passwords to be generated.

  2. alphabet = "abcdefghijklmnopqrstuvwxyzZXCVNMLKJHGFDSAPOIUYTREWQ123456789/*-+": This line initializes a string variable alphabet containing all lowercase and uppercase letters of the alphabet, as well as some special characters and numbers.

  3. passwords = []: This initializes an empty list named passwords to store the generated passwords.

pythonCopy code    for length in pwlength:
        password = ""
        for _ in range(length):
            next_letter_index = random.randrange(len(alphabet))
            password += alphabet[next_letter_index]

        password = replaceWithNumber(password)
        password = replaceWithUppercaseLetter(password)

        passwords.append(password)

    return passwords
  1. for length in pwlength:: This initiates a loop over each length value in the pwlength list.

  2. password = "": This initializes an empty string password to store the generated password.

  3. for _ in range(length):: This loop runs length times, generating a password of the specified length.

  4. next_letter_index = random.randrange(len(alphabet)): This generates a random index within the range of the alphabet string.

  5. password += alphabet[next_letter_index]: This appends a randomly selected character from the alphabet string to the password.

  6. password = replaceWithNumber(password): This line calls the replaceWithNumber function to replace some characters in the password with numbers.

  7. password = replaceWithUppercaseLetter(password): This line calls the replaceWithUppercaseLetter function to replace some characters in the password with uppercase letters.

  8. passwords.append(password): This appends the generated password to the passwords list.

pythonCopy codedef replaceWithNumber(pword):
    for _ in range(random.randrange(1, 3)):
        replace_index = random.randrange(len(pword) // 2)
        pword = pword[:replace_index] + str(random.randrange(10)) + pword[replace_index + 1:]
    return pword
  1. def replaceWithNumber(pword):: This defines a function named replaceWithNumber that takes a string pword as input and replaces some characters with random numbers.

  2. for _ in range(random.randrange(1, 3)):: This loop iterates a random number of times between 1 and 2.

  3. replace_index = random.randrange(len(pword) // 2): This generates a random index within the first half of the pword.

  4. pword = pword[:replace_index] + str(random.randrange(10)) + pword[replace_index + 1:]: This line replaces the character at replace_index with a random number.

  5. return pword: This returns the modified password.

pythonCopy codedef replaceWithUppercaseLetter(pword):
    for _ in range(random.randrange(1, 3)):
        replace_index = random.randrange(len(pword) // 2, len(pword))
        pword = pword[:replace_index] + pword[replace_index].upper() + pword[replace_index + 1:]
    return pword
  1. def replaceWithUppercaseLetter(pword):: This defines a function named replaceWithUppercaseLetter that takes a string pword as input and replaces some characters with random uppercase letters.

  2. for _ in range(random.randrange(1, 3)):: This loop iterates a random number of times between 1 and 2.

  3. replace_index = random.randrange(len(pword) // 2, len(pword)): This generates a random index within the second half of the pword.

  4. pword = pword[:replace_index] + pword[replace_index].upper() + pword[replace_index + 1:]: This line replaces the character at replace_index with its uppercase equivalent.

  5. return pword: This returns the modified password.

pythonCopy codedef main():
    st.title("Random Password Generator")

    numPasswords = st.number_input("How many passwords do you want to generate?", min_value=1, step=1, value=1)

    st.write("Generating " + str(numPasswords) + " passwords")

    passwordLengths = []
    min_length = 3
    st.write(f"Minimum length of password should be {min_length}")

    for i in range(numPasswords):
        length = st.number_input(f"Enter the length of Password #{i + 1}", min_value=min_length, step=1,
                                 value=min_length)
        passwordLengths.append(length)

    if st.button("Generate Passwords"):
        Passwords = generatePassword(passwordLengths)

        for i, password in enumerate(Passwords):
            st.write(f"Password #{i + 1}: {password}")

if __name__ == "__main__":
    main()
  1. def main():: This defines the main function of the program.

  2. st.title("Random Password Generator"): This sets the title of the Streamlit app to "Random Password Generator".

  3. numPasswords = st.number_input("How many passwords do you want to generate?", min_value=1, step=1, value=1): This line creates a number input widget where the user can specify how many passwords they want to generate.

  4. st.write("Generating " + str(numPasswords) + " passwords"): This line displays a message indicating the number of passwords that will be generated.

  5. passwordLengths = []: This initializes an empty list to store the lengths of the passwords specified by the user.

  6. min_length = 3: This sets the minimum length of a password to 3 characters.

  7. st.write(f"Minimum length of password should be {min_length}"): This line displays a message indicating the minimum length requirement for a password.

  8. for i in range(numPasswords):: This loop iterates over the number of passwords specified by the user.

  9. length = st.number_input(f"Enter the length of Password #{i + 1}", min_value=min_length, step=1, value=min_length): This line creates a number input widget for each password, allowing the user to specify the length of each password.

  10. passwordLengths.append(length): This appends the length of each password to the `


With these simple steps, you can create a secure random password generator app using Streamlit. The app allows users to easily generate strong passwords.