Register
It is currently Sat Oct 25, 2014 1:41 pm

random password generator


All times are UTC - 6 hours


Post new topic Reply to topic  [ 10 posts ] 
Author Message
 PostPosted: Thu Aug 17, 2006 10:07 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
do you need a new password?
can't come up with one?
run this script with a parameter saying how long of a password you want...
you can add letters or symbols to the array at the top (just make sure you use a \ where bash will try and read it as something else)
Code:
#!/bin/bash
# call like rndpwd.sh 5
# will generate a password that is 5 characters long

pwdlen=$1

char=(0 1 2 3 4 5 6 7 8 9 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 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 ! @ \# $ % ^ \&)

max=${#char[*]}

for i in `seq 1 $pwdlen`
do

        let rand=${RANDOM}%${max}
        str="${str}${char[$rand]}"
done
echo $str


Top
 Profile  
 PostPosted: Thu Aug 17, 2006 1:46 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
Code:
#!/bin/bash
# Random password generator.
# Originally by jbsnake, modified by crouse to use Upper case letters as well.
# Now also does error checking and fails if the input isn't numerical integers or
# if no input is given at all.

if [[ -z "$1" || $1 = *[^0-9]* ]];
  then
   echo " ";
   echo "      ######### COMMAND FAILED ########## ";
   echo "      USAGE: $0 passwordlength";
   echo "      EXAMPLE: $0 10";
   echo "      Creates a random password 10 chars long.";
   echo "      ######### COMMAND FAILED ########## ";echo " ";
   exit
  else
   pwdlen=$1
   char=(0 1 2 3 4 5 6 7 8 9 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 A B C D E F G H I J K L M N O P Q R S T U V X W Y Z)
   max=${#char[*]}
   for i in `seq 1 $pwdlen`
      do
           let "rand=$RANDOM % 62"
      str="${str}${char[$rand]}"
      done
   echo $str
fi


Edit.......
Excellent idea btw........
Too many people use crackable passwords


Top
 Profile WWW  
 PostPosted: Thu Aug 17, 2006 2:27 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
Added in a security notice about passwords less than 6 characters in length.....

Code:
#!/bin/bash
# Random password generator.
# Originally by jbsnake, modified by crouse to use Upper case letters as well.
# Now also does error checking and fails if the input isn't numerical integers or
# if no input is given at all.

if [[ -z "$1" || $1 = *[^0-9]* ]];
  then
   echo " ";
   echo "      ######### COMMAND FAILED ########## ";
   echo "      USAGE: $0 passwordlength";
   echo "      EXAMPLE: $0 10";
   echo "      Creates a random password 10 chars long.";
   echo "      ######### COMMAND FAILED ########## ";echo " ";
   exit
  else
   if [[ "$1" -lt "6" ]]
   then echo "Your password is less than 6 characters in length."
         echo "This is a security risk. Suggested length is 6 characters or longer !"
   fi
   
   pwdlen=$1
   char=(0 1 2 3 4 5 6 7 8 9 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 A B C D E F G H I J K L M N O P Q R S T U V X W Y Z)
   max=${#char[*]}
   for i in `seq 1 $pwdlen`
      do
           let "rand=$RANDOM % 62"
      str="${str}${char[$rand]}"
      done
   echo $str
fi


Top
 Profile WWW  
 PostPosted: Fri Aug 18, 2006 4:42 am   
User avatar

Joined: Mon Jul 03, 2006 8:58 pm
Posts: 52
Location: Rochester, NY
So how do you guys remember your generated passwords?

I usually "generate" my passwords with a trick that I was taught once to create hard to crack but easy to remember passwords:

1. Think of a phrase that's easy to remember such as "Mary had a little lamb"
2. Truncate each word to a minimum of one character so that the remaining letters (minus whitespace) is at lest the desired password size (Mahaalila - desired size of 8)
3. Randomly choose some letters to capitalize - but in a manner you can remember (mAhaALila)
4. Change some of the letters into numbers like "l33t sp33k" (mAhAL1l4)

Now you have a secure password that's much easier to remember than a random generation of alphanumerics. This procedure could be modified to account for symbols as well.

An interesting twist on this script would be to take a phrase, apply the above algorithm, and spit back a "random" password that might be easier to remember.


Top
 Profile WWW  
 PostPosted: Fri Aug 18, 2006 12:16 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
He he he have at it ;)

You could have it generate 10 at a time or something like that too.... so you could pick one that is more memonic. ..... i think that's a word .... lol :lol:

I think jbsnake initially just dreamt this up to help create random passwords for himself.. and it's kinda taken a mind of it's own ;) I really like it, because i use these types of passwords....that aren't prone to dictionary attact, and even though they are harder to remember, they are much more secure. .... sometimes it's hard to create several non-dictionary passwords and be totally random while doing it... this makes it very easy.


Top
 Profile WWW  
 PostPosted: Fri Aug 18, 2006 1:32 pm   
User avatar

Joined: Mon Jul 03, 2006 8:58 pm
Posts: 52
Location: Rochester, NY
Yeah, most of my passwords are ba***rd stepchildren of 1337 5p33k - not as radical or methodical, but the same idea to make an otherwise dictionary word turn into a non-dictionary word. I also play with capitalization and punctuation.

Sometimes I just find a quick and easy pattern on the keyboard to type that includes numbers, symbols and letters but otherwise means nothing. For example - one time I had a password like: aw3edji9ol -- try telling that one to tech help over the phone. :lol:


Top
 Profile WWW  
 PostPosted: Wed Sep 13, 2006 11:50 pm   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
Well, since this is a thread for password generators, I'll add one I came up with just last month. (Hope you don't mind, jbsnake.) This has a few bells and whistles, along with sanity checks. 8)
However, the actual generator I came up with is very fast and does a good job of creating random characters..... :idea:

The features include:
    * Allows for generating one or more passwords at a time
    * You can specify a fixed length or a length range (min-max), within limits
    * When a range is specified, along with more than one password, the length of each password will also be random 8)
    * And did I say it was fast? ;-)

Anyway, enough with the hype. It is well commented to make it easier to follow along:
Code:
#! /bin/bash
################################################################################
# genpass - a random password generator
#
# Written by CTWaley (aka, thegeekster),  (c) August 2006
#
# You may do anything you want with this script, as long as the line directly
# above remains with it.  Which means, give credit where credit is due!
#
################################################################################

## Self explanatory what this is for ;-)
print_usage(){
  cat<<_USAGE_
      Usage: ${0##*/} [-n #] length
             ${0##*/} [-n #] min-max

Genpass creates passwords whose length is N, with an optional number
of passqwords to generate (-n #).  If an optional range is given
(min-max), the length of the password will be randomly chosen within
that range, inclusively.  And if more than one password is requested,
the length will be different for each password generated.

NOTE: The range cannot be lower than 6 or greater than 15 (6-15), as
this is the acceptable limits for most websites or user logins."
_USAGE_
}

## The generator "engine" - what all the fuss is about :-D
gen_pass(){  echo $(tr -dc "$CHARS" </dev/urandom | head -c $1)  ;}

## First off, we must have something to work with from the command line:
test -z "$*"  &&  print_usage >&2  &&  exit 1   ## If empty, show usage and bail

## This is needed to produce alphanumeric characters independent of locale
## (ie., characters that are not part of the "extended" ascii chart) when using
## the [:alnum:] character class:
export LC_ALL=C

## Reseed the $RANDOM variable, using the PID of this script (which changes each
## time the script runs).  This should produce a much more random generation of
## numbers from the $RANDOM variable with each run of the script:
RANDOM=$$

## CHARS is for the characters you want to include in your password, such as
## letters, numbers, and punctuation.  IMPORTANT: If using a dash, it must be the
## last character, or 'tr' will complain:
CHARS='[:alnum:]_!()$@#&+=-'

## Do we have a request for more than one password?
if [[ "$1" =~ "^-c" ]]; then
    ## Chop off the option switch in $1 to see if NUM is appended to the switch
    NUM="${1/-c/}";  if [ -z "$NUM" ]; then
        ## If NUM is empty, assign $2 to NUM and shift the command args twice
        NUM="$2"  &&  shift 2
        test -z $NUM  &&  ## Make sure NUM is not empty
            { echo -e "\n Not enough arguments on the command line.\n"  &&  exit;}
    else   ## It must not be empty, so we'll only need to shift once
        shift 1
    fi

    ## Do we have a valid number to work with and not any non-digit characters:
    [[ "$NUM" =~ "[^0-9]" ]]  &&
        { echo -e "\n '$1' is not a valid whole number for the number of passwords to generate.\n"
          print_usage >&2  &&  exit 1;}

    ## Now, after all the shifting around, do we have any args left?:
    test -z "$1"  &&  print_usage >&2  &&  exit 1  ## Oops, we forgot the LEN (or NUM)

else  ## Here we don't have any request for more than one password, so we'll need just one
    NUM=1
fi
    ## Well, if we made it this far, then everything must be okay (so far)

## Okay, are we dealing with a specified length or have a range to work with?
if [[ "$1" =~ "-" ]]; then   ## If true, we're dealing with a random length (range)
    ## We'll assign the range to an array, if a range was specified in the argument.
    RANGE=(${1/-/ })   ## Convert the dash to a space when assigning to an array

    ## Testing for min/max length requirements:
    test ${RANGE[0]} -lt 6 -o ${RANGE[1]} -gt 15  &&
      { printf '%s\n' '' ' Sorry, but the acceptable length for a password is 6-15 characters.' \
        ' (Note - some sites will only allow passwords no greater then 12' \
        ' characters in length.) :-(' '' >&2
        exit 1;}

    ## Now we will produce the actual random length(s) within the specified range:
    for ((INT=1 ; INT<=NUM ; INT++)); do  ## We're looping for the NUM of passwords
        SEED=$RANDOM
        LEN=$((((SEED %= (RANGE[1] - RANGE[0])) + 1) + RANGE[0]))
        gen_pass $LEN
    done

else   ## If not a number range, then we only have one length to deal with:
    for ((INT=1 ; INT<=NUM ; INT++)); do  ## Again, loop for the NUM of passwords
        gen_pass $1
    done
fi

exit 0



---thegeekster :)


Top
 Profile  
 PostPosted: Mon Oct 09, 2006 3:19 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
thought i should add in a little more flexibility... just for kicks...
Code:
#!/bin/bash

usage="$0 [options] #
   Options:
            u - include upper case letters
            l - include lower case letters
            n - include numbers
            s - include symbols

   Example: $0 lun 5
   Example: $0 s 15
   Example: $0 lns 9"

if [[ $# > 2 ]]
then
        echo "*** You can't have that many options!"
        echo "$usage"
        exit
fi

if [[ $# < 1 ]]
then
        echo "*** You must atleast specify a length!"
        echo "$usage"
        exit
fi

tags=$1
pwdlen=$2

upcase="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"
num="0 1 2 3 4 5 6 7 8 9"
lowcase="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"
sym="! @ \# $ % ^ &"
tmp=""

isNum=`echo $pwdlen | sed 's#[0-9]##g'`
if [[ ! -z "$isNum" ]]
then
        echo "$pwdlen is not a number!"
        echo "$usage"
        exit
fi

numFlags=${#tags}

for i in `seq 0 $((numFlags - 1))`
do
        case ${tags:$i:1} in
                u)      tmp="$upcase $tmp";
                        ;;
                n)      tmp="$num $tmp";
                        ;;
                l)      tmp="$lowcase $tmp";
                        ;;
                s)      tmp="$sym $tmp";
                        ;;
                *)      echo "${tags:$i:1} is not a usable flag!";
                        echo "$usage";
                        exit;
                        ;;
        esac
done

char=($tmp)

max=${#char[*]}

if [[ ! $max > 0 ]]
then
        echo "You must choose atleast one type of character set to continue!"
        echo "$usage"
        exit
fi

for i in `seq 1 $pwdlen`
do

        let rand=${RANDOM}%${max}
        str="${str}${char[$rand]}"
done
echo $str


Top
 Profile  
 PostPosted: Mon Oct 09, 2006 3:57 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
I like it :)


Top
 Profile WWW  
 PostPosted: Thu Nov 16, 2006 5:26 am   

Joined: Thu Nov 16, 2006 5:10 am
Posts: 2
this is my simplified random password generator

Code:
#!/bin/bash
# random password generator
# by Mixacha
cat /dev/urandom | tr -cd a-zA-Z0-9 | fold -w8 | head -n 10


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP