Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. # ***************************************************************************
  2. # This function encode a sting in md5 hash of 32 characters. You can short
  3. # the length with the second parameter.
  4. #
  5. #  @param string $1 string (required)
  6. #  @param integer $2 length (option, default: 32)
  7. #  @return string
  8. #  @example:    md5 "Hello World" 8
  9. function md5() {
  10.   local length=${2:-32}
  11.   local string=$( echo -n "$1" | md5sum | awk '{ print $1 }' )
  12.   echo ${string:0:${length}}
  13. }