#!/usr/bin/env bash

brt_pass() {
  local length="${1:-20}"
  if ! [[ "$length" =~ ^[0-9]+$ ]] || (( length < 8 )); then
    length=20
  fi
  if command -v openssl &>/dev/null; then
    openssl rand -base64 48 | tr -dc 'A-Za-z0-9!@#$%^&*' | head -c "$length"
    echo
  else
    head -c 256 /dev/urandom | tr -dc 'A-Za-z0-9!@#$%^&*' | head -c "$length"
    echo
  fi
}
