| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2249 人关注过本帖
标题:登陆验证
只看楼主 加入收藏
SecretX
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2008-7-31
收藏
得分:0 
LZ,请您自己看书,如果您看书看不懂的话,说明您应该是没有这方面的基础,请您从基础学起
2008-11-19 13:35
谁与争瘋
Rank: 2
等 级:论坛游民
帖 子:360
专家分:14
注 册:2008-11-18
收藏
得分:0 
本美女向来说话算话
2008-11-19 13:44
andy560225
Rank: 1
来 自:天上
等 级:新手上路
帖 子:72
专家分:0
注 册:2008-10-29
收藏
得分:0 
你说的这句话=废话
算话就帮我写个吧
2008-11-19 16:52
606liutong
Rank: 2
等 级:论坛游民
威 望:2
帖 子:740
专家分:94
注 册:2006-10-9
收藏
得分:0 
可是你把程序代码敲10遍了么?


前程——漆黑如这落寞的夜,苦苦守望,却总也望不到那泛着点点苍白的黎明!期望与希冀!无奈与魂殇!
獨自壹個人,望著大海淚流.
愛情,不敢奢望...
2008-11-19 16:54
谁与争瘋
Rank: 2
等 级:论坛游民
帖 子:360
专家分:14
注 册:2008-11-18
收藏
得分:0 
对啊 你把程序敲10遍了么?

唉 现在的人啊
2008-11-19 16:55
andy560225
Rank: 1
来 自:天上
等 级:新手上路
帖 子:72
专家分:0
注 册:2008-10-29
收藏
得分:0 
我没书啊,更别说例子了
要是有书也不麻烦你们了
电子书的例子也不全
就只写了重点........
2008-11-19 17:10
andy560225
Rank: 1
来 自:天上
等 级:新手上路
帖 子:72
专家分:0
注 册:2008-10-29
收藏
得分:0 
美女你受点累
帮帮我这个菜鸟吧
2008-11-19 17:18
谁与争瘋
Rank: 2
等 级:论坛游民
帖 子:360
专家分:14
注 册:2008-11-18
收藏
得分:0 
建议你去淘本书吧 也不贵20 30块钱

能让你学习的速度加快几倍
2008-11-19 20:24
sun_life
Rank: 1
等 级:新手上路
帖 子:356
专家分:5
注 册:2006-5-29
收藏
得分:0 
在登录事件中

c_characterManipulation MDI_characterManipulation = new c_characterManipulation();  //创建c_characterManipulation的类对象

            if (txt_name.Text.Trim() == "")
            {
                MessageBox.Show("用户名不能为空,请重新输入!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
            else if (txt_pwd.Text == "")
            {
                MessageBox.Show("密码不能为空,请重新输入!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
            else if (txt_name.Text.Trim().Length < 3 && txt_name.Text.Trim().Length > 16)    //设定用户名的长度在4-16之间
            {
                MessageBox.Show("用户名长度应该在4-16个字符之间!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
            else if(txt_pwd.Text.Length<3 && txt_pwd.Text.Length>16)    //设定密码长度在4-16之间
            {
                MessageBox.Show("密码长度应该在6-16个字处之间!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
            else if (!MDI_characterManipulation.b_IfCharacter(txt_name.Text.Trim()))     //判断用户名输入是否合法
            {
                MessageBox.Show("用户名不合法,请求重新输入!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (MDI_characterManipulation.if_blank(txt_name.Text.Trim()))
            {
                MessageBox.Show("用户名中不能有空格,重新输入!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                txt_name.Text = "";

                txt_pwd.Text = "";
            }
            else if (!MDI_characterManipulation.b_IfCharacter(txt_pwd.Text))        //密码不能有单引号
            {
                MessageBox.Show("用户名、密码错误,请重新输入!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                txt_name.Text = "";

                txt_pwd.Text = "";
            }
            else
            {
                c_login MDI_Login = new c_login(txt_name.Text.Trim(), MDI_characterManipulation.str_Apostrophe(txt_pwd.Text));     //创建c_login的类对象

                if (!MDI_Login.b_userVerification())        //判断用户信息表中有没有此用户
                {
                    if (!MDI_Login.b_Students())         //判断学生信息表中有没有此学号
                    {
                        MessageBox.Show("用户名或密码错误,请重新输入!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);

                        txt_name.Text = "";

                        txt_pwd.Text = "";
                    }
                    else if (!MDI_Login.b_Spwd())       //判断学生密码是不是正确
                    {
                        MessageBox.Show("用户名或密码错误,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        txt_name.Text = "";

                        txt_pwd.Text = "";
                    }
                    else
                    {
                        Frm_MDI MDI = new Frm_MDI(txt_name.Text.Trim());        //创建“Frm_MDI”对象,同时将用户名输入框中的内容传到“Frm_MDI”页面

                        this.Hide();         //隐藏当前窗口

                        MDI.Show();          //显示“Frm_MDI”窗口
                    }
                }
                else if (!MDI_Login.b_pwdVerification())
                {
                    MessageBox.Show("用户名或密码错误,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    Frm_MDI MDI = new Frm_MDI(txt_name.Text.Trim());        
                    this.Hide();      

                    MDI.Show();         
                }
            }           


c_login类


using System;
using System.Collections.Generic;
using System.Text;

using System.Data;              //所有的一般数据访问类         
using System.Data.Sql;          //用于SQL Server数据访问的通用新接口和类
using System.Data.SqlClient;    //SQL Server提供程序的类
using System.Data.SqlTypes;     //SQL Server数据类型
using System.Data.Odbc;

using System.Configuration;     //在项目中要添加对System.Configuration的引用

namespace StudentManagementSystem
{
    class c_login
    {
        SqlConnection conn = new SqlConnection("server=.;pwd=sun;user id=sa;database=SIM");     //数据库连接

        SqlCommand cmd = new SqlCommand();

        SqlDataReader dr;

        string str_userName;

        string str_pwd;

        public c_login(string username,string pwd)
        {
            str_userName = username.Trim();    //接收用户框输入的用户名

            str_pwd = pwd;      //接收用户框输入的密码
        }

        public bool b_Students()    //判断登录名是不是学号
        {
            bool b_TF;

            try
            {
                conn.Open();

                = "select t_number from tb_studentInfo where t_number='"+ str_userName +"'";    //按用户名查找学号

                cmd.Connection = conn;

                dr = cmd.ExecuteReader();

                if (dr.Read())
                {
                    b_TF = true;
                }
                else
                {
                    b_TF = false;
                }
                conn.Close();

                return b_TF;
            }
            finally
            {
                conn.Close();
            }
        }

        public bool b_Spwd()        //按学好查找密码
        {
            bool b_TF;

            try
            {
                conn.Open();

                = "select t_pwd from tb_studentInfo where t_number='" + str_userName + "'";     //按学好查密码

                cmd.Connection = conn;

                dr = cmd.ExecuteReader();

                if (dr.Read())
                {
                    b_TF = true;
                }
                else
                {
                    b_TF = false;
                }
                conn.Close();

                return b_TF;
            }
            finally
            {
                conn.Close();
            }
        }

        public bool b_userVerification()        //判断用户名正确性,查到后返回真
        {
            bool b_user;

            try
            {
                conn.Open();

                = "select t_UserName from tb_UserInfo where t_UserName='" + str_userName + "' collate Chinese_PRC_CS_AI_WS ";   //查找用户名时区分大小写、不区分重音、区分宽度

                cmd.Connection = conn;

                dr = cmd.ExecuteReader();       //执行SQL查询语句

                if (dr.Read())
                {
                    b_user = true;
                }
                else
                {
                    b_user = false;
                }
                conn.Close();
            }
            finally
            {
                conn.Close();
            }
            return b_user;
        }

        public string  str_pwdVerification()        //返回数据库中的密码
        {
            string strPwd = "";

            try
            {
                conn.Open();

                = "select t_pwd from tb_UserInfo where t_UserName='" + str_userName + "' and t_pwd='" + str_pwd + "' collate Chinese_PRC_CS_AI_WS ";   //查找密码时区分大小写、不区分重音、区分宽度

                cmd.Connection = conn;

                dr = cmd.ExecuteReader();

                if (dr.Read())
                {
                    strPwd = dr["t_pwd"].ToString();    //返回密码字段
                }
                else
                {
                    strPwd = "";
                }
                conn.Close();
            }
            finally
            {
                conn.Close();
            }
            return strPwd;
        }

        public bool b_pwdVerification()     //判断密码正确性,查到后返回真
        {
            bool b_pwd;

            try
            {
                conn.Open();

                = "select t_pwd from tb_UserInfo where t_UserName='" + str_userName + "' and t_pwd='" + str_pwd + "' collate Chinese_PRC_CS_AI_WS ";   //查找密码时区分大小写、不区分重音、区分宽度

                cmd.Connection = conn;

                dr = cmd.ExecuteReader();        //执行SQL查询语句

                if (dr.Read())
                {
                    b_pwd = true;
                }
                else
                {
                    b_pwd = false;
                }
                conn.Close();
            }
            finally
            {
                conn.Close();
            }
            return b_pwd;
        }
    }
}

c_characterManipulation这个类就算了,你把关于这个类中的方法判断的全删掉就可以了,我在我的项目上考来的,高手给看看怎么改,效率会更高!

当知道自己后才知道什么是可怕!
2008-11-19 22:43
乖老鼠
Rank: 5Rank: 5
来 自:四川省
等 级:职业侠客
威 望:2
帖 子:434
专家分:394
注 册:2008-9-8
收藏
得分:0 
LZ为什么不去看教程呢?我给你发的帖子的教程是版主写的很详细的

转眼就从编程菜鸟混成了半灌水
2008-11-20 08:33
快速回复:登陆验证
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027806 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved