[BASH] Script pour générer des mots de passe
Voici un petit script fait pour ceux qui doivent maintenir des serveurs et créer des mots de passe rapidement :
#!/bin/bash
# random password generator# Sets the maximum size of the password the script will generate
MAXSIZE=40 # <<——- You can change valuearray1=(‘a’ ‘b’ ‘c’ ‘d’ ‘e’ ‘f’ ‘g’ ‘h’ ‘i’ ‘j’ ‘k’ ‘l’ ‘m’ ‘n’ ‘o’ ‘p’ ‘q’ ‘r’ ‘s’ ‘t’ ‘u’ ‘v’ ‘w’ ‘x’ ‘y’ ‘z’ ‘0’ ‘1’ ‘2’ ‘3’ ‘4’ ‘5’ ‘6’ ‘7’ ‘8’ ‘9’ ‘0’ ‘A’ ‘B’ ‘C’ ‘D’ ‘E’ ‘F’ ‘G’ ‘H’ ‘I’ ‘J’ ‘K’ ‘L’ ‘M’ ‘N’ ‘O’ ‘P’ ‘Q’ ‘R’ ‘S’ ‘T’ ‘U’ ‘V’ ‘W’ ‘X’ ‘Y’ ‘Z’ ‘!’ ‘£’ ‘$’ ‘%’ ‘&’ ‘=’ ‘.’ ‘,’ ‘;’ ‘:’ ‘-‘ ‘_’)
# Used in conjunction with modulus to keep random numbers in range of the array size
MODNUM=$# Keeps track of the number characters in the password we have generated
pwd_len=0# Bash’s command substitution syntax to store the results of the tput command
term_clear=$(tput clear)# Stores the number of lines or rows on the terminal display
max_lines=$(tput lines)# Stores the number of columns on the terminal display
max_cols=$(tput cols)# Finds the appropriate spot to indent for horizontally centered output
indent=$(( ((max_cols / 2)) – ((MAXSIZE / 2)) ))# Finds the vertical center of the terminal.
line_num=$(( max_lines / 2 ))# Clear the screen
echo $term_clear# The outer while loop starts at 0 and loops till MAXSIZE, creating a passwd char each iteration.
# The shells $RANDOM variable creates a semi-random unsigned number. This is our entropy. =x
# x simply holds some random unsigned int that will be used to make the character scramble.
# 500 was choosen for speed and nothing else. Leave out the mod 500 if you want or change it.
# The inner loop displays the password characters. Tput keeps the cursor in the proper position.
# Mod MODNUM keeps the random number inside the size of the array so it doesnt over index.
while [ $pwd_len -lt $MAXSIZE ]
do
x=$(($RANDOM%500))
y=0
while [ $y -lt $x ]
do
((y++))
index=$(($RANDOM%$MODNUM))
tput cup $line_num $(( indent + pwd_len ))
echo -n « ${array1[$index]} »
done
((pwd_len++))
done# Place the cursor at the bottom of the screen –where is usually at.
tput cup $max_lines 0exit 0
En espérant qu’il serve