Skip to content

Commit

Permalink
Added password generator shell file to exercises folder (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
tungbq authored Apr 3, 2024
2 parents c934662 + 083fec1 commit 77ed60a
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 77ed60a

Please sign in to comment.