Password Generator

De Wiki Clusterlab.com.br
Ir para navegação Ir para pesquisar
  • Generate password with sixteen characters
  • At least one special character
  • At least two numbers
  • At least two lowercase letters
  • At least two uppercase letters
function generate_password() {
    while true
    do 
        export SENHA=$(tr -dc 'A-Za-z0-9!?@#_' < /dev/urandom | head -c 16 | xargs) ;
        # echo $SENHA
        if [[ $(echo $SENHA | egrep "\!|@|#|_|\?"  | sed -e "s/./&\n/g" | wc -l ) -ne 0 &&  $(echo $SENHA  | sed -e "s/./&\n/g" | grep "[0-9]" | wc -l ) -gt 2 && $(echo $SENHA  | sed -e "s/./&\n/g" | grep "[a-z]" | wc -l ) -gt 2 && $(echo $SENHA  | sed -e "s/./&\n/g" | grep "[A-Z]" | wc -l ) -gt 2 ]]
        then 
            break
        fi
    done
    echo $SENHA 
}