Skip to content

Instantly share code, notes, and snippets.

@Rycieos
Created December 18, 2020 15:32
Show Gist options
  • Save Rycieos/d187d856c674ae40fa68a32644c8db39 to your computer and use it in GitHub Desktop.
Save Rycieos/d187d856c674ae40fa68a32644c8db39 to your computer and use it in GitHub Desktop.
password
#!/usr/bin/env bash
# Create a randomly generated password
echo "\
1. alpha
2. alpha + digit
3. alpha + digit + special
4. alpha + digit + space
5. alpha + digit + special + space
6. alpha + digit + limited
"
read -rp 'Type: ' type
case "${type}" in
1)
class='[:alpha:]'
;;
2)
class='[:alnum:]'
;;
3)
class='[:graph:]'
;;
4)
class='[:alnum:] '
;;
5)
class='[:print:]'
;;
6)
class='[:alnum:].!@#$%^&*-'
;;
*)
exit 1
;;
esac
read -rp 'Number of characters: ' chars
LC_ALL=C tr -dc "${class}" < /dev/urandom | head -c"${chars}"
printf '\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment