#! /bin/ksh

#
# Name        : ${HOME}/bin/RotatePassword
#
# Version     : 1.0
#
# Author      : Gerard van Wageningen
#
# Description : Rotate the current password to avoid defining
#               a new one each month.
#
#		3004-602 The required password characteristics are:
#		        a maximum of 3 repeated characters.
#		        a minimum of 3 characters not found in old password.
#		        a minimum of 1 alphabetic character.
#		        a minimum of 1 non-alphabetic character.
#		        a minimum of 8 characters in length.
#		
# 1.0   First Version
#

\whence set_debug 1>/dev/null 2>&1 && eval $( set_debug ${0##*/} )

typeset -i i=0
set -A str
export ORG_PASSWORD=''
export OLD_PASSWORD=''
export NEW_PASSWORD=''

str[ 0]='!qaz1QAZ'
str[ 1]='@wsx2WSX'
str[ 2]='#edc3EDC'
str[ 3]='$rfv4RFV'
str[ 4]='%tgb5TGB'
str[ 5]='^yhn6YHN'
str[ 6]='&ujm7UJM'
str[ 7]='*ik,8IK<'
str[ 8]='(ol.9OL>'
str[ 9]=')p;/0P:?'

str[10]='1QaZCqAz'
str[11]='2WsX@wSx'
str[12]='3EdC#eDc'
str[13]='4RfV$rFv'
str[14]='5TgB%tGb'
str[15]='6YhN^yHn'
str[16]='7UjM&uJm'
str[17]='8Ik<*iK,'
str[18]='9Ol>(oL.'
str[19]='0P:?)p;/'

function UpdatePassword
{
  return
} # function UpdatePassword

stty -echo
read ORG_PASSWORD?"Geef huidig password: "
stty echo
print
OLD_PASSWORD="${ORG_PASSWORD}"

while (( i <  ${#str[*]} ))
do
  NEW_PASSWORD="${str[i]}"
  print "${i}: ${OLD_PASSWORD} -> ${NEW_PASSWORD}"
  UpdatePassword || exit 1
  OLD_PASSWORD="${NEW_PASSWORD}"
  i=1+i
  sleep 1
done

NEW_PASSWORD="${ORG_PASSWORD}"
print "${i}: ${OLD_PASSWORD} -> ${NEW_PASSWORD}"
UpdatePassword || exit 1

print "Huidig password reset!"

exit 0

############### EOF ###############
