From 083fec168202ac55d6e0d4cf464cf20f3a5c9f55 Mon Sep 17 00:00:00 2001 From: Jonathanlemon Date: Tue, 2 Apr 2024 12:06:40 -0400 Subject: [PATCH] Added password generator shell file to exercises folder --- .../answers/02_password_generator.sh | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 topics/shell/advanced/excercise/answers/02_password_generator.sh diff --git a/topics/shell/advanced/excercise/answers/02_password_generator.sh b/topics/shell/advanced/excercise/answers/02_password_generator.sh new file mode 100644 index 0000000..1e75dd9 --- /dev/null +++ b/topics/shell/advanced/excercise/answers/02_password_generator.sh @@ -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 \ No newline at end of file