shell腳本的應用——用戶登錄驗證程序
1.腳本裏創建兩個用戶名和密碼
2.讓用戶從屏幕輸出賬戶和密碼進行登錄
3.如果賬戶輸入錯誤,讓他繼續輸入
4.賬戶輸入正確,輸入密碼
5.密碼正確,登錄成功
6.同一個賬號,密碼最多錯三次,三次都錯將鎖定賬戶。(此時腳本不能退出)
7.鎖定賬號以後,讓他繼續可以登錄未鎖賬號
#!/bin/bash
useradd jinchuan1
if [ $? -eq 0 ];then
echo "123" | passwd --stdin jinchuan1
fi
useradd jinchuan2
if [ $? -eq 0 ];then
echo "456" | passwd --stdin jinchuan2
fi
a="jinchuan1"
b="jinchuan2"
c="123"
d="456"
while :
do
while :
do read -p "請輸入用戶名:" A
if [ $A == $a ];then
break
fi
if [ $A == $b ];then
break
fi
done
if [ $A == jinchuan1 ];then
for i in 1 2 3
do read -p "請輸入密碼" C
if [ $C == $c ];then
echo "登錄成功"
break
fi
[ $i == 3 ] && passwd -l $A && echo "用戶已經鎖定"
done
fi
if [ $A == jinchuan2 ];then
for i in 1 2 3
do read -p "請輸入密碼" C
if [ $C == $d ];then
echo "登錄成功"
break
fi
[ $i == 3 ] && passwd -l $A && echo "用戶已經鎖定"
done
fi
done
shell腳本的應用——用戶登錄驗證程序