Skip to content

Commit

Permalink
Added password generator shell file to exercises folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathanlemon committed Apr 2, 2024
1 parent c934662 commit 083fec1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions topics/shell/advanced/excercise/answers/02_password_generator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Function to generate random password
generate_password() {
# Define the characters to use for generating password
characters="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+="

# Initialize variable to store generated password
password=""

# Generate random password
for i in {1..30}; do
# Get a random character from the list of characters
random_char=${characters:RANDOM % ${#characters}:1}
# Append the random character to the password
password="${password}${random_char}"
done

# Print the generated password
echo "$password"
}

# Call the function to generate password
generate_password

0 comments on commit 083fec1

Please sign in to comment.