Winform窗体验证登陆
用户名,密码尽量不要在BLL,UIL判断,尽可能的在储存过程判断,通过返回的值不同,进行判断,这样提高安全性
SQL Server储存过程代码:
BEGIN
if(exists ( select User_ID from SYS_User
where LTRIM(RTRIM(User_Name))=LTRIM(RTRIM(@User_Name)) ))
BEGIN if(exists ( select User_ID from SYS_User
where LTRIM(RTRIM(User_Name))=LTRIM(RTRIM(@User_Name)) and
LTRIM(RTRIM(User_PassWord))=LTRIM(RTRIM(@User_PassWord))))
BEGIN if (exists(select User_ID from SYS_User
where LTRIM(RTRIM(User_Name))=LTRIM(RTRIM(@User_Name)) and
LTRIM(RTRIM(User_PassWord))=LTRIM(RTRIM(@User_PassWord)) and
UserType_ID=@UserType_ID))
BEGIN select User_Name,UserType_ID from SYS_User
where LTRIM(RTRIM(User_Name))=LTRIM(RTRIM(@User_Name)) and
LTRIM(RTRIM(User_PassWord))=LTRIM(RTRIM(@User_PassWord)) and
UserType_ID=@UserType_ID
end
else
begin
select -3;------------用户类型错误
end
end
else
BEGIN
select -1;------------密码错误
end
end
else
BEGIN
select -2;---------用户名不存在
end
END
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
BLL代码:
public DataSet Login(string username,string password,int type) {
//加密密码
password = Utils.GetMd5HashStr(password);
SqlParameter[] sqlPams = {
new SqlParameter("@type",SqlDbType.NChar),
new SqlParameter("@User_Name",SqlDbType.NChar),
new SqlParameter("@User_PassWord",SqlDbType.NChar),
new SqlParameter("@UserType_ID",SqlDbType.Int),
};//声明SQL参数数组并实例化相关参数
sqlPams[0].Value = "DengLuYanZheng";//对参数赋值
sqlPams[1].Value = username;//对参数赋值
sqlPams[2].Value = password;//对参数赋值
sqlPams[3].Value = type;//对参数赋值
DataSet dateset = new DataSet();
DataTable dt = dal.QueryDataTable("Frm_Login", sqlPams);
dateset.Tables.Add(dt);
//myDAL.DAL_SelectDB_Par("存储过程的名字",SQL参数数组);
return dateset;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
UIL代码:
private void but_Login_Click(object sender, EventArgs e)
{
var userName = UserName.Text.Trim();
var password = Password.Text.Trim();
int type = Convert.ToInt32(SelectType.SelectedValue);
DataTable LoginData = bll.Login(userName, password, type).Tables[0];
int type_int = Convert.ToInt32(LoginData.Rows[0][0]);
//判断
switch (type_int)
{
case -1:
{
MessageBox.Show("密码错误!!!", "提示",MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
break;
}
case -2:
{
MessageBox.Show("账号不存在,请联系管理员!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
break;
}
case -3:
{
//
MessageBox.Show("用户类型不对应!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
break;
}
default:
{
this.Hide();
Main main = new Main();
main.Show();
break;
}
}
}
---------------------
Winform窗体验证登陆的更多相关文章
- C#中WinForm窗体事件的执行次序
C#中WinForm窗体事件的执行次序如下: 当 Windows Form 应用程序启动时,会以下列顺序引发主要表单的启动事件: System.Windows.Forms.Control ...
- 小例子(二)、winform窗体间的关系
写一个关于winform窗体间的关系 1.登陆,思路:登陆后隐藏登陆窗体,关闭Form2时结束整个应用程序. //登陆窗体 private void button2_Click(object send ...
- WinForm窗体项目 之 MySchool管理系统终极版
学习WinForm窗体程序也有一段时间了,今天就来尝试着来一个项目热热身~ 在我们通常使用的MySchool管理中,不外乎这几种功能:增.删.改.查.改密码 在过去的C#中确实是挺简单的,但是在学习了 ...
- winform 窗体圆角设计
网上看到的很多winform窗体圆角设计代码都比较累赘,这里分享一个少量代码就可以实现的圆角.主要运用了System.Drawing.Drawing2D. 效果图 代码如下. private void ...
- WinForm 窗体属性 窗体美化
WinForm是·Net开发平台中对Windows Form的一种称谓. Windows窗体的一些重要特点如下: 功能强大:Windows窗体可用于设计窗体和可视控件,以创建丰富的基于Windows的 ...
- winform窗体置顶
winform窗体置顶 金刚 winform 置顶 今天做了一个winform小工具.需要设置置顶功能. 网上找了下,发现百度真的很垃圾... 还是必应靠谱些. 找到一个可以链接. https://s ...
- winform窗体控件(全)
回顾跟补充下除了昨天那常用6个其他的winform窗体控件作用 1:Button:按钮 (1)AutoSize:如果是True的情况下,内容将会撑开:False的话会另起一行 (2)Enabled: ...
- C#将exe运行程序嵌入到自己的winform窗体中
以下例子是将Word打开,然后将它嵌入到winform窗体中,效果如下图:C将exe运行程序嵌入到自己的winform窗体中 - kingmax_res - iSport注意:该方法只适用于com的e ...
- Winform 窗体单例
有窗体Form1和窗体Form2,单击Form1上按钮,只弹出一个Form2. Form2里自定义一个方法,里面判断是否弹出Form2,没有时弹出Form2. public static Form2 ...
随机推荐
- 迭代器-iteration
class CoffrrIterator implements Iterator<Coffee> { int cunt = size; public boolean hasNext() { ...
- Ubuntu 12.10终端Terminal快捷方式调用
1:使用快捷键:ctrl+alt+t 打开终端 2:在终端上右键,选“Lock to launcher” 这样就锁定在左侧了,需要用时,直接点就打开了.
- Vim升华之树形目录插件NERDTree安装图解【转】
本文转载自:http://www.linuxidc.com/Linux/2013-06/86048.htm 无意中看到实验室的朋友使用的vim竟然能在左边显示树形目录,感觉很方便,这样子文件夹有什么文 ...
- CentOS 7下Keepalived + HAProxy 搭建配置详解
第一步:准备 1. 简介 本文搭建的是利用 Keepalived 实现 HAProxy 的热备方案,即两台主机上的 HAProxy 实例同时运行,其中全总较高的实例为 MASTER,MASTER出现异 ...
- 浅谈Linux Kernel 中循环链表的实现
前阵子在弄缓存的时候,我们需要将qemu对于磁盘镜像文件写请求串成一个链表,最终将这个链表里面的写请求全部刷回到镜像文件里面,那么我们便需要一个强健,可靠的链表的接口,于是我们仿照Linux 2.4. ...
- [USACO 2017DEC] Haybale Feast
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=5142 [算法] 首先用RMQ预处理S数组的最大值 然后我们枚举右端点 , 通过二分求 ...
- 【转】axios全攻略
随着 vuejs 作者尤雨溪发布消息,不再继续维护vue-resource,并推荐大家使用 axios 开始,axios 被越来越多的人所了解.本来想在网上找找详细攻略,突然发现,axios 的官方文 ...
- gdb core调试
原文链接 http://blog.163.com/lanka83/blog/static/32637615200801793020182/http://blog.csdn.net/taina2008/ ...
- jsDoc 使用及配置!
原文地址:http://www.cnblogs.com/hxling/archive/2012/11/27/2791067.html jsDoc 说白了就是帮助你生成JS的文档,但有个前提,就是你编写 ...
- Oracle:ORA-12154: TNS:could not resolve the connect identifier specified
ORA-12154: TNS: 无法解析指定的连接标识符 注册表:regedit 安装oracle后用Net Manager 配置好服务名称之后,测试成功,可是PL/SQL无法连接 http://we ...