shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] Gerar senha


From: Viktor Mota
Subject: Re: [shell-script] Gerar senha
Date: Fri, 18 Jun 2004 09:39:43 -0300

Olá Caio Ferreira,

quinta-feira, 17 de junho de 2004, 15:16:46, você escreveu:

CF> All

CF> Por acaso alguem sabe a onde posso encontrar um shell-script que crie
CF> senha ?!?!?

=============================================================================
#!/bin/bash
# May need to be invoked with  #!/bin/bash2  on older machines.
#
# Random password generator for Bash 2.x by Antek Sawicki <address@hidden>,
# who generously gave permission to the document author to use it here.
#
# ==> Comments added by document author ==>


MATRIX="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
#MATRIX="0123456789"
#MATRIX="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#MATRIX="abcdefghijklmnopqrstuvwxyz"
#MATRIX="aeiou"

# ==> Password will consist of alphanumeric characters.
# ==> May change 'LENGTH' for longer password.
LENGTH="8"


while [ "${n:=1}" -le "$LENGTH" ]
# ==> Recall that := is "default substitution" operator.
# ==> So, if 'n' has not been initialized, set it to 1.
do
        PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"

        # ==> Very clever, but tricky.

        # ==> Starting from the innermost nesting...
        # ==> ${#MATRIX} returns length of array MATRIX.

        # ==> $RANDOM%${#MATRIX} returns random number between 1
        # ==> and [length of MATRIX] - 1.

        # ==> ${MATRIX:$(($RANDOM%${#MATRIX})):1}
        # ==> returns expansion of MATRIX at random position, by length 1.
        # ==> See {var:pos:len} parameter substitution in Chapter 9.
        # ==> and the associated examples.

        # ==> PASS=... simply pastes this result onto previous PASS 
(concatenation).

        # ==> To visualize this more clearly, uncomment the following line
        #                 echo "$PASS"
        # ==> to see PASS being built up,
        # ==> one character at a time, each iteration of the loop.

        let n+=1
        # ==> Increment 'n' for next pass.
done

echo "$PASS"      # ==> Or, redirect to a file, as desired.

exit 0
=============================================================================

[]s
Viktor Mota
address@hidden

--- tagline ---
O cúmulo... Da Rapidez: Fechar a gaveta, trancar e jogar a chave dentro.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]