generating password in sh

generating password in sh enjoy
mail@pastecode.io avatar
unknown
sh
2 months ago
836 B
13
Indexable
Never
#!/bin/bash

# Function to generate a random password
generate_password() {
    # Define the character set for the password
    char_set="A-Za-z0-9!@#$%^&*()_+=-"
    
    # Generate a password of length 12
    password=$(head /dev/urandom | tr -dc "$char_set" | head -c 12)
    
    echo "$password"
}

# Function to display the menu
display_menu() {
    echo "Menu:"
    echo "1. Generate Random Password"
    echo "2. Exit"
}

# Main script
while true; do
    display_menu
    read -p "Enter your choice: " choice

    case $choice in
        1)
            echo "Random Password: $(generate_password)"
            ;;
        2)
            echo "Exiting..."
            exit 0
            ;;
        *)
            echo "Invalid choice. Please enter a valid option."
            ;;
    esac
done
Leave a Comment