| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1415 人关注过本帖
标题:C#中如果实现和数据库的密码比对?
只看楼主 加入收藏
水似骄阳
Rank: 1
来 自:云南大理学院
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-12-14
收藏
 问题点数:0 回复次数:5 
C#中如果实现和数据库的密码比对?
我是用Access,我想让用户输入的口令和数据库里数据进行比对,如果正确则可以进入,否则不能.并且还要能修改密码!请帮帮我,告诉我要怎么实现?
搜索更多相关主题的帖子: 数据库 密码 里数 口令 Access 
2007-12-14 22:14
huwei1024
Rank: 1
等 级:禁止发言
帖 子:149
专家分:0
注 册:2007-4-12
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽

www.
2007-12-14 22:46
andey
Rank: 2
等 级:新手上路
威 望:4
帖 子:938
专家分:0
注 册:2007-7-18
收藏
得分:0 
for循环一下就ok

msdn == 葵花宝典!!!
QQ:122768959
2007-12-17 15:29
一刀客
Rank: 1
等 级:新手上路
帖 子:181
专家分:0
注 册:2007-10-26
收藏
得分:0 
这个是SQL的写法,希望对你有用~
if (String.IsNullOrEmpty(txtuser.Text) || String.IsNullOrEmpty(txtpwd.Text))
            { MessageBox.Show("输入帐号/密码再登录", "错误提示"); return; }
            int i, flag = 0;
            string ConnectStr="server=localhost;database=mydata;uid=sa;pwd=;";
            string str1 = txtuser.Text; string str2 = txtpwd.Text;
            string StrSel = "select * from [db_user]";
            string strRow1 = null; string strRow2 = null;
            SqlConnection MyCon=new SqlConnection(ConnectStr);
            MyCon.open();
            SqlCommand MyCom=new SqlCommand(StrSel,MyCon)
            SqlDataAdapter MyDataAdapter=new SqlDataAdapter(MyCom);
            DataSet MyDs=new DataSet;
            MyDataAdapter.Fill(MyDs,"db_user");
            for (i = 0; i < MyDs.Tables["db_user"].Rows.Count; i++)
            {
                strRow1 = MyDs.Tables["db_user"].Rows[i]["user"].ToString();
                strRow2 = MyDs.Tables["db_user"].Rows[i]["pwd"].ToString();
                if (str1 == strRow1 && str2 == strRow2)
                {
                    flag = 1;
                    break;
                }
            }
            if (flag == 1)
            {
                     MessageBox.Show("登录成功!","提示");
                     MyCon.Closed();
                     this.Closed();      
            }
            else
            {
                MessageBox.Show("帐号/密码错误");
                txtuser.Focus();
            }

责人之心责己 宽己之心宽人
2007-12-18 08:15
tanxiaolin
Rank: 1
等 级:新手上路
帖 子:71
专家分:0
注 册:2007-12-12
收藏
得分:0 
private void button1_Click(object sender, EventArgs e)
        {
            string UserCode = textBox1.Text.Trim();
            string UserPswd = textBox2.Text.Trim();
            if (UserCode=="")
            {
                MessageBox.Show("请输入帐号");
            }
            else {
                SqlDataReader usdr = FPara.SqlReader("select top 1 * from lampUserName where UserName='" + UserCode + "'", FPara.connStr);
                if (usdr != null)
                {
                    if (usdr.Read())
                    {
                        if (usdr["Pswd"].ToString() != UserPswd)
                        {
                            MessageBox.Show("密码错误");
                        }
                        else
                        {
                            FPara.ShopCode = usdr["UserName"].ToString();
                            MessageBox.Show("登录成功");
                            this.Hide();
                            Form4 f = new Form4();
                            f.Show();

                        }
                    }
                    else
                    {
                        MessageBox.Show("帐号密码错误");
                    }
                    usdr.Close();



namespace UserData
{
    public class FPara
    {
        public static string ShopCode="";
        public static bool CheckLogin()
        {
            if(ShopCode=="")
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        public static SqlConnection connStr=new SqlConnection("Server=XTZJ-674B0F596D\\SQLEXPRESS;uid=sa;pwd=123456;database=master");
        public static SqlDataReader SqlReader(string sql,SqlConnection connstr)
        {
            SqlDataReader sqldr=null;
            SqlCommand cmd=new SqlCommand(sql,connstr);
            if (cmd.Connection.State.ToString()=="Closed") cmd.Connection.Open();
            try
            {
                sqldr=cmd.ExecuteReader();
            }
            catch(Exception e)
            {
                if (e!=null) sqldr=null;
            }
            return sqldr;
        }
        //数据库操作连接
        public static string SqlCmd(string sql,SqlConnection connstr)
        {
            string errorstr=null;
            SqlCommand sqlcmd= new SqlCommand(sql,connstr);
            if (sqlcmd.Connection.State.ToString()=="Open") sqlcmd.Connection.Close();
            sqlcmd.Connection.Open();
            try
            {
                sqlcmd.ExecuteNonQuery();
            }
            catch(Exception e)
            {
                if (e!=null) errorstr=e.ToString();
            }
            sqlcmd.Connection.Close();
            return errorstr;
        }
    }
}
2007-12-18 09:55
soonce
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-12-23
收藏
得分:0 
吸收了一点,剩下的打包慢慢研究!
2007-12-23 02:13
快速回复:C#中如果实现和数据库的密码比对?
数据加载中...
 
   



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

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