shell登陸驗證

#!/bin/bash
function login(){
echo "請輸入帳號:"
read user
echo "請輸入密碼:"
read pass
}
function check_login(){
login
i=$((i+1))
user=`echo $user|sed -e 's/^/\"/g' -e 's/$/\"/g'`
t_user=(`mysql -uroot -p8b4cf0qaz  op -e "select t_user,t_pass  from user where t_user=${user} " `)
if [ $i -lt 3 ];then
 if [ ${#t_user[@]}  -gt 1  ];then
   if [ $pass == ${t_user[3]} ];then
      echo "歡迎${user}!"
   else
     check_login
   fi
 else
   echo "帳號不存在"
 fi
else
 echo "密碼輸入錯誤次數超過三次,程序退出"
 exit 1
fi
}
check_login

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章