-
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added password generator shell file to exercises folder
- Loading branch information
1 parent
c934662
commit 083fec1
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
topics/shell/advanced/excercise/answers/02_password_generator.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |