Welcome to Nik Maslov`s blog
« Update to specific OpenSolaris versionTerminus font in OpenSolaris »

Password generator in OpenSolaris/Solaris

Permalink 07/29/09 10:44, by Nik Maslov, Categories: Welcome

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
##############################################################################


11 comments »

11 comments

Comment from: me first [Visitor]
first
03/01/10 @ 20:45
Comment from: how to download from redtube [Visitor] · http://www.youtube.com/watch?v=z_og6fACN-g
Good work, keep us posting, you are good writer.
03/24/10 @ 01:48
Great post, I totally agree. How long have you been blogging for now, I really like the look of your site. Cheers, Tradeking Review
03/27/10 @ 18:06
Comment from: dieta kopenhaska [Visitor] · http://www.youtube.com/watch?v=Vx1WM5OziaE
Just want to tell you that your website content is interesting, but you must improve site design
03/27/10 @ 19:05
Comment from: sportingbet promotional code [Visitor] · http://www.buzzfeed.com/redtubevids/sportingbet-promotional-code-14gc
I came across your article, i think your website is interesting, keep us posting.
03/29/10 @ 00:44
Comment from: save vidoeo from redtube [Visitor] · http://tnij.org/flvdirect
I came across your site, i think your blog is interesting, keep us posting.
04/02/10 @ 12:33
Comment from: gry planszowe [Visitor] · http://gry-planszowe.c0.pl
I've shared you article on digg, good work
04/03/10 @ 15:51
great i tend to agree with what you said. http://www.rapidsloth.com/Easy-MP3-Recorder-v1.30.html has users that raise this topic and give reviews. i find it interesting and its wroth a read.
04/08/10 @ 14:47
Comment from: randki ogloszenia [Visitor] · http://randkisexzone.blogspot.com
Just want to tell you that your www content is interesting, but you must improve site design
05/04/10 @ 20:18
Comment from: Linda [Visitor] · http://www.takesneakers.com
I simply wanted to say your web site is one of the nicely laid out, most inspirational I have come across in quite a while. Thx! :)
06/17/10 @ 09:15
Comment from: legal steroid [Visitor] · http://topmusclesupplements.org
Very interesting info, i am waiting for more ! Keep updating your site and you will have a lot o readers
08/10/10 @ 20:10

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)

Search

XML Feeds

StatCounter

blog software

©2010 by Nik Maslov

Contact | Blog templates by Asevo | blogtool | dedicated hosting | evoTeam