1. 程式人生 > >簡單的使用者登入選單

簡單的使用者登入選單

選單欄:

指令碼內容:

#!/bin/bash

function Enter() {

for q in {1..100}
do
 read -p "請輸入賬號:" a
 grep -h $a /root/www(使用者及密碼存放檔案) >> /dev/null
 if [ $? == 0 ]
 then
  echo "使用者名稱正確"
  for y in 1 2 3
  do   
   read -p  "請輸入密碼:" b
   grep -h $a /root/www > /root/linshi(臨時存放使用者及密碼檔案)


   grep -o $b /root/linshi >> /dev/null
                        if [ $? == 0 ]
                        then

                                echo "密碼正確" && exit
                        elif [ $? -ne 0 ]

                        then
                                echo "密碼錯誤"
                        fi
  done
  user=??? && echo "使用者已鎖定"
 else
  grep -h $a /root/www >> /dev/null
  if [ $? == 0 ]
  then
   echo "使用者名稱正確"
  else
   echo "使用者名稱錯誤" && continue
  fi
  for n in {1..3}
  do
   read -p  "請輸入密碼:" d
   if [ $d == 0 ]
   then
    echo "密碼正確" && exit
   elif [ $d -ne 0 ]
   then
    echo "密碼錯誤"
   fi
  done
  user1=??? && echo "使用者已被鎖定"
 fi
 if [ $user == ??? ] && [ $user1 == ??? ]
 then
  exit
 fi
done
}

function Login() {

read -p "請輸入註冊賬號:" num
grep -o $num /root/www >> /dev/null
if [ $? == 0 ]
then
 echo "此使用者已存在"
else
 read -p "請輸入註冊密碼:" mmm
 echo "$num:$mmm" >> /root/www
 echo "使用者建立成功"
fi
}

function Delete() {

read -p "請輸入刪除賬戶:" num
sed -i '/^'$num'/d' /root/www
if [ $? == 0 ]
then
  echo "該使用者已刪除"
fi
}
function Exit() {

echo "已退出"

}

function menuitem() {
clear
cat << FOF
  *************************
  *   *
  * 1.Enter  *
  * 2.Login  *
  * 3.Delete *
  * 4.Exit  *
  *   *
  *************************
FOF
read -p "請輸入驗證碼:" p

case $p in
 1)
  Enter
  ;;
 2)
  Login
  sleep 2
  menuitem
  ;;
 3)
  Delete
  sleep 2
  menuitem
  ;;
 4)
  Exit
  ;;
 *)
  echo "請驗證是否正確"
  ;;
esac
}
menuitem