Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Mac Terminal – Random Readable Password

Posted on February 1, 2017 By David Kittell

I recently was challenged to create a random readable password for Mac OS. While I designed this for Mac OS it’s likely it will work with little to no changes on any UNIX system.

Password format was two digit number then a word followed by another word with special characters with a period as the delimiter.

Example: 99.G0ats.L1ve

# Password Format:
# ##.Word$.Oth3r
# Numbers. Word with Caps and Special Character.Word again
# 12-20 Characters in length

# Get two digit random number - Start
sPWDPart1=$(cat /dev/urandom | env LC_CTYPE=C tr -dc 0-9 | head -c 2; echo)
#echo $sPWDPart1
# Get two digit random number - Stop

# Get Random Word - Start
function GetRandomWord()
{
sWord1=$(cat -n /usr/share/dict/words | grep -w $(jot -r 1 1 $n) | cut -f2)
chrlen=${#sWord1}
#echo $chrlen
if [ $chrlen -lt 4 ];
then
GetRandomWord
elif [ $chrlen -gt 8 ];
then
GetRandomWord
fi
#echo $sWord1
}

function GetRandomWordMod()
{
GetRandomWord
#echo $sWord1
sWord2=$(echo "$(tr '[:lower:]' '[:upper:]' <<< ${sWord1:0:1})${sWord1:1}")
if [[ $sWord2 == *"a"* ]]; then
sWord3=$(echo "$sWord2" | sed 's/a/@/g')
elif [[ $sWord2 == *"e"* ]]; then
sWord3=$(echo "$sWord2" | sed 's/e/3/g')
elif [[ $sWord2 == *"i"* ]]; then
sWord3=$(echo "$sWord2" | sed 's/i/1/g')
elif [[ $sWord2 == *"o"* ]]; then
sWord3=$(echo "$sWord2" | sed 's/o/0/g')
elif [[ $sWord2 == *"u"* ]]; then
sWord3=$(echo "$sWord2" | sed 's/u/_/g')
elif [[ $sWord2 == *"y"* ]]; then
sWord3=$(echo "$sWord2" | sed 's/y/-/g')
fi
#echo $sWord3
}
# Get Random Word - Stop

GetRandomWordMod
sPWDPart2=$sWord3

GetRandomWordMod
sPWDPart3=$sWord3

sFullPWD=$(echo "$sPWDPart1.$sPWDPart2.$sPWDPart3")

echo "Write down this ${#sFullPWD} character password:\n$sFullPWD"
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code Mac OS X Shell Mac OSX UNIX UNIX Shell Scripts

Post navigation

Previous post
Next post

Related Posts

PowerShell – Get Application Pool Username and Password

Posted on November 12, 2015

cd IIS:\AppPools (Get-Item DemoSite).processModel (Get-Item DemoSite).processModel.username (Get-Item DemoSite).processModel.password All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it…

Read More

PowerShell – REST Client with Basic Authentication

Posted on December 22, 2015February 12, 2016

First listed source code is without authentication, whereas the second is with basic authentication param ( [Parameter( Mandatory=$true)] [string]$Address ) clear function Get-MAC() { param($Address) begin { $APIURL = "http://<URL>/address.xml?&search=" $resource = "$($APIURL)$($Address)" $mac = Invoke-RestMethod -URI $resource -Method Get $hash = @{ Status_Code = $mac.Response.Status_Code Company_Name = $mac.Response.Company_Name MAC_Address…

Read More

MSSQL DateTime Conversions

Posted on June 23, 2014December 26, 2018

Sometimes a basic function like MSSQL Format Date Function can not work as you do not have permission to create a function or you simply need something quick. To get day of week from DateTime column and order it by the proper day of week order. This is rather easy…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes