Advertisement
Guest User

Untitled

a guest
Oct 31st, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.07 KB | None | 0 0
  1. #!/bin/bash
  2. u=0
  3. p=0
  4. e=0
  5. for arg in "$@"
  6. do
  7.     if [ "$arg" == "-u" ] && [ "$u" == 0 ]
  8.     then
  9.         u=1
  10.         continue
  11.     fi
  12.     if [ "$u" == 1 ]
  13.     then
  14.         if [[ "$arg" =~ ^[A-Za-z0-9]{1,}$ ]]
  15.         then
  16.                 user=$arg
  17.         else
  18.                 echo "Username is not valid!"
  19.                 exit 1
  20.         fi
  21.         u=2
  22.     fi
  23.    
  24.     if [ "$arg" == "-p" ] && [ "$p" == 0 ]
  25.     then
  26.         p=1
  27.         continue
  28.     fi
  29.     if [ "$p" == 1 ]
  30.     then
  31.         if [ ${#arg} -lt 3 ]
  32.         then
  33.                 echo "Password is to short!"
  34.                 exit 1
  35.         fi
  36.         if [[ "$arg" =~ [A-Z] ]]
  37.         then
  38.             ok=1
  39.         else
  40.             echo "Password $arg is insecure!"
  41.             exit 1
  42.         fi
  43.         if [[ "$arg" =~ ^[A-Za-z0-9._%+-]{1,}$ ]]
  44.         then
  45.                 pass=$arg
  46.         fi
  47.         p=2
  48.     fi         
  49.  
  50.     if [ "$arg" == "-e" ] && [ "$e" == 0 ]
  51.     then
  52.         e=1
  53.         continue
  54.     fi
  55.     if [ "$e" == 1 ]
  56.     then
  57.         if [[ "$arg" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$ ]]
  58.         then
  59.                 email=$arg
  60.         else
  61.                 echo "Email is not valid!"
  62.                 exit 1
  63.         fi
  64.         e=2
  65.     fi
  66. done
  67.  
  68. if [ "$p" == 0 ]
  69. then
  70.     echo "User $user has email $email"
  71. else
  72.     echo "User $user has the email $email and password $pass"
  73. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement