# 创建库
root@localhost [tu] >create database tu;
## 进入库
use tu;
# 创建表结构
CREATE TABLE `tiao` (
`ip` int(10) unsigned zerofill NOT NULL AUTO_INCREMENT COMMENT 'ip区分',
`name` varbinary(5) NOT NULL COMMENT '用户昵称',
`password` varbinary(20) NOT NULL COMMENT '用户密码',
`qx` enum('1','2','3') DEFAULT NULL COMMENT '用户权限(默认没有)(1,运维2,开发3,测试)',
PRIMARY KEY (`ip`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Database changed
root@localhost [tu] >show tables;
+--------------+
| Tables_in_tu |
+--------------+
| tiao |
+--------------+
1 row in set (0.00 sec)
root@localhost [tu] >select * from tiao;
+------------+------+----------+------+
| ip | name | password | qx |
+------------+------+----------+------+
| 0000000001 | hhh | 123 | 1 |
| 0000000002 | ttt | 456 | 2 |
| 0000000003 | ccc | 789 | 3 |
| 0000000004 | mmm | 111 | NULL |
+------------+------+----------+------+
4 rows in set (0.00 sec)
# 登录脚本
[root@db04 ~]# cat tiao.sh
#!/bin/bash
denlu() {
username=$(whiptail --title "用户登录" --inputbox "请输入用户名:" 8 60 3>&1 1>&2 2>&3)
account=$(mysql -uroot -p123 -e "select name from tu.tiao where name='${username}';"| awk 'NR==2')
if [[ -z $account ]]; then
whiptail --title "错误" --msgbox "账户不存在,请创建一个新账户。" 10 50
exit 1
fi
password=$(mysql -uroot -p123 -e "select * from tu.tiao where name='${username}'" | awk 'NR==2{print $3}')
role=$(mysql -uroot -p123 -e "select * from tu.tiao where name='${username}'" | awk 'NR==2{print $4}')
entered_password=$(whiptail --title "用户登录" --passwordbox "请输入密码:" 8 60 3>&1 1>&2 2>&3)
if [[ $entered_password == $password ]]; then
whiptail --title "登录成功" --msgbox "密码正确,欢迎回来!" 10 50
else
entered_password=$(whiptail --passwordbox "密码错误,请重新输入。" --title "错误" 10 50 3>&1 1>&2 2>&3)
if [[ $entered_password == $password ]]; then
whiptail --title "登录成功" --msgbox "密码正确,欢迎回来!" 10 50
else
whiptail --title "错误" --msgbox "密码错误,请检查密码是否正确。密码记录在/root/tu/a.txt文件中,请确认。请重新登录。" 10 50
exit 1
fi
fi
case $role in
"1"|"ops")
whiptail --title "ops" --msgbox "666" 10 50
exit 1
;;
"2"|"dev")
whiptail --title "dev" --msgbox "aaa" 10 50
exit 1
;;
"3"|"test")
whiptail --title "test" --msgbox "hhh" 10 50
exit 1
;;
*)
whiptail --title "错误" --msgbox "连职位都没有还混什么" 10 50
exit 1
;;
esac
}
zc() {
zcname=$(whiptail --title "注册信息" --inputbox "要注册哪个用户名:" 8 60 3>&1 1>&2 2>&3)
zcount=$(mysql -uroot -p123 -e "select name from tu.tiao where name='${zcname}';"| awk 'NR==2')
if [[ -z $zcount ]]; then
if [[ $zcname = *[[:space:]]* ]];then
whiptail --title "错误" --msgbox "用户名不要输入空格" 10 50
zc
fi
zcpassword=$(whiptail --title "注册信息" --passwordbox "请输入密码:" 8 60 3>&1 1>&2 2>&3)
if [[ $zcpassword = *[[:space:]]* ]];then
whiptail --title "错误" --msgbox "密码不要输入空格" 10 50
zc
elif echo "$zcpassword" | grep -qP '[\p{Han}]';then
whiptail --title "错误" --msgbox "密码不支持中文" 10 50
zc
else
mysql -uroot -p123 -e "insert into tu.tiao (name, password) VALUES ('${zcname}', '${zcpassword}');"
zcount=$(mysql -uroot -p123 -e "select name from tu.tiao where name='${zcname}';"| awk 'NR==2')
if [[ -z $zcount ]]; then
whiptail --msgbox "创建未成功" 10 50
exit
else
whiptail --msgbox "创建完成" 10 50
denlu
fi
fi
else
whiptail --title "错误" --msgbox "账户存在,请更换一个。" 10 50
zc
fi
}
abtt() {
options=("注册" "" "登录" "" "退出" "")
selected_option=$(whiptail --title "$ada $username 请选择功能模块" --menu "请输入功能数字:" 15 50 9 "${options[@]}" 3>&1 1>&2 2>&3)
exitstatus=$?
if [[ $exitstatus -eq 0 ]]; then
case $selected_option in
"注册")
zc
;;
"登录")
denlu
;;
"退出")
return
;;
esac
else
whiptail --msgbox "用户点击了取消,但是并无卵用。" 10 50
abtt
fi
}
abtt
标签:10,登录,title,--,数据库,50,whiptail,msgbox,图形化
From: https://www.cnblogs.com/xiutai/p/17749287.html