| « Update to specific OpenSolaris version | Terminus font in OpenSolaris » |
Password generator in OpenSolaris/Solaris
Some time ago, when I was administering Debian (which is actually my favorite linux distro) I spent a lot of time adding users to SVN, CVS and other systems that required password generation. In Debian there were pre-instaleld pwgen programm, which generated simple, yet secure passwords.
In Solaris/OpenSolaris, there is no such preinstalled programm, but I found this tiny, but very useful script for password generation. No more "keyboard-generation-style" passwords ![]()
#!/bin/ksh
# Random password generator.
# Pass in the length of the password to generate.
#
# by Michael Roth, 2006
#set -x
RANDOM=$$
if [ "$#" -ne "1" ]; then
echo "Usage: ${0##*/} PASSWORDLENTGH"
echo "\te.g. ${0##*/} 8"
exit 1
fi
if [ ! -z `echo "$1" | tr -d "[:digit:]"` ]; then
echo "Usage: ${0##*/} PASSWORDLENTGH"
echo "\te.g. ${0##*/} 8"
echo "\nError: PASSWORDLENGTH must be a number!"
exit 1
fi
if [ ! "$1" -gt "0" ]; then
echo "Usage: ${0##*/} PASSWORDLENTGH"
echo "\te.g. ${0##*/} 8"
echo "\nError: PASSWORDLENGTH must be greater then 0!"
exit 1
fi
#
# Main
#
# Modify STRING as source
STRING='q w e r t y u i o p a s d f g h j k l z x c v b n m Q W E R T Y U I O P A S D F G H J K L Z X C V B N M 1 2 3 4 5 6 7 8 9 0 _ - ! ? = '
# password length
LENGTH="$1"
typeset -i index
index=1
IFS_SAV="$IFS"
IFS=" "
# Put $STRING in an array
for i in `echo $STRING`
do
array[$index]=$i
((index=index+1))
done
string_len=${#array[*]}
IFS="$IFS_SAV"
typeset -i pwlen
pwlen=0
PASS=""
while [ "$pwlen" -lt "$LENGTH" ]
do
index=$(($RANDOM % $string_len))
PASS="$PASS${array[$index]}"
((pwlen=pwlen+1))
done
echo "Your password: $PASS"
exit 0
##############################################################################
### This script is submitted to BigAdmin by a user of the BigAdmin community.
### Sun Microsystems, Inc. is not responsible for the
### contents or the code enclosed.
###
###
### Copyright Sun Microsystems, Inc. ALL RIGHTS RESERVED
### Use of this software is authorized pursuant to the
### terms of the license found at
### http://www.sun.com/bigadmin/common/berkeley_license.jsp
##############################################################################