北肙

当你不能够再拥有,唯一可以做的,就是令自己不要忘记。

Script to Generate Password for Linux

Requirement: The length of the string must be 12 bits The password must contain numbers, lowercase letters, uppercase letters and at least one special characters Special characters include: ><+-{}:.&; For script, see below: #!/bin/bash # # used for create password. # function random_num() { head -5 /dev/urandom | md5sum | grep -o "[0-9]" | sed -n […]

Requirement:

  • The length of the string must be 12 bits
  • The password must contain numbers, lowercase letters, uppercase letters and at least one special characters
  • Special characters include: ><+-{}:.&;

For script, see below:

#!/bin/bash
#
# used for create password.
#
function random_num()
{
  head -5 /dev/urandom | md5sum | grep -o "[0-9]" | sed -n '1p'
}
function random_lowcase()
{
  head -5 /dev/urandom | md5sum | grep -o "[a-z]" | sed -n '1p'
}
function random_uppercase()
{
  random_lowcase | tr '[a-z]' '[A-Z]'
}
function random_symbol()
{
  case $(random_num) in
  1)
  echo ">"
  ;;
  2)
  echo "<"
  ;;
  3)
  echo "+"
  ;;
  4)
  echo "-"
  ;;
  5)
  echo "{"
  ;;
  6)
  echo "}"
  ;;
  7)
  echo ":"
  ;;
  8)
  echo "."
  ;;
  9)
  echo "&"
  ;;
  0)
  echo ";"
  ;;
  esac
}
n_num=`head -5 /dev/urandom | md5sum | grep -o "[1-8]" | sed -n '1p'`
n_lowcase=`head -5 /dev/urandom | md5sum | grep -o "[1-$((10-n_num))]" | sed -n '1p'`
n_uppercase=`head -5 /dev/urandom | md5sum | grep -o "[1-$((11-n_num-n_lowcase))]" | sed -n '1p'`
n_symbol=$((12-n_num-n_lowcase-n_uppercase))
function str_num()
{
  for((i=1;i<="$n_num";i++))
  do
    echo -e ""$(random_num)"\c"
  done
}
function str_lowcase()
{
  for((i=1;i<="$n_lowcase";i++))
  do
    echo -e ""$(random_lowcase)"\c"
  done
}
function str_uppercase()
{
  for((i=1;i<="$n_uppercase";i++))
  do
    echo -e ""$(random_uppercase)"\c"
  done
}
function str_symbol()
{
  for((i=1;i<="$n_symbol";i++))
  do
    echo -e ""$(random_symbol)"\c"
  done
}
function which_to_print()
{
  if [[ $1 -eq 1 ]]; then
    str_num
  elif [[ $1 -eq 2 ]]; then
    str_lowcase
  elif [[ $1 -eq 3 ]]; then
    str_uppercase
  else
    str_symbol
  fi
}
function random_print1()
{
  n=0
  for((I=1;I<=2;I++)); do
    tmp=`head -5 /dev/urandom | md5sum | grep -o "[1-2]" | sed -n '1p'`
    if [[ n -ne tmp ]]; then
      n=$tmp
      which_to_print $n
    else
      while [[ $n -eq $tmp ]]; do
        tmp=`head -5 /dev/urandom | md5sum | grep -o "[1-2]" | sed -n '1p'`
      done
      n=$tmp
      which_to_print $n
    fi
  done
}
function random_print2()
{
  n=0
  for((I=1;I<=2;I++)); do
    tmp=`head -5 /dev/urandom | md5sum | grep -o "[3-4]" | sed -n '1p'`
    if [[ n -ne tmp ]]; then
      n=$tmp
      which_to_print $n
    else
      while [[ $n -eq $tmp ]]; do
        tmp=`head -5 /dev/urandom | md5sum | grep -o "[3-4]" | sed -n '1p'`
      done
      n=$tmp
      which_to_print $n
    fi
  done
}
random_print1
random_print2
echo

Download Link

Leave a Reply

Your email address will not be published. Required fields are marked *