This is a quick and dirty example of using hashes. I use it for this wiki.

The following generates a hash. Note the use of date +%s to get the current unix time, and dividing by 3600 to effectively round to the nearest hour, and the use of this in the hash. There is need for a secret string to come in from somewhere. Doing things like this is not secure if somebody else has root access to your Linux machine, btw, since environment variables can be read via /proc.

Anyway, the output is a string of hex digits which is specific to the unix time, to the nearest hour, and the Ip address. I use this as a means to authorise certain Ip address ranges to make changes (and possibly also requiring a password).


NOW="$(date +%s)"
SALT="$(echo -n "$S" | sha256sum | cut -c1-64 | xxd -r -p | base64)"
IP="$(dig TXT +short | tr -d '\"')"
echo "Hashing $INP"
Z="$(echo -n "$INP" | sha256sum | cut -c1-64)"
echo "$Z"