DES加密和MD5完全不是一回事,你代码里全混了。
MD5也不是加密。数据库保存密码的MD5值。
用户登录时,输入的密码也做MD5,然后和数据库里的比较是否一致即可。

解决方案 »

  1.   

          
            private globalData da = new globalData(); //我把连接写在了globalData类里,用来调用
            Net.Common.Method des = new Net.Common.Method();//Method是我写的DES类
           
            public Form1()
            {
                InitializeComponent();
            }        public void button1_Click(object sender, EventArgs e)
            {            string userid = textBox1.Text.Trim();//用户名
                string userpassword = textBox2.Text.Trim();//密码
                if (userid == "" && userpassword == "")
                {
                    MessageBox.Show("用户名和密码不能为空!", "提示",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (userid == "")
                {
                    MessageBox.Show("用户名不能为空!", "提示",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (userpassword == "")
                {
                    MessageBox.Show("密码不能为空!", "提示",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                string sql = "select count(*) from WDK_PT_UserInfo where userid='" + userid + "' and userpassword='" + userpassword + "'";
                SqlCommand cmd = new SqlCommand(sql, da.link());
                try
                {
                    int i = 0;
                    i = (int)cmd.ExecuteScalar();
                    if (i > 0)
                    {
                        Form2 f = new Form2();//Form2是修改密码窗体
                        f.Show();
                        f.flag = textBox2.Text.Trim();
                        f.flag2 = textBox1.Text.Trim();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误!");
                        this.textBox1.Clear();
                        this.textBox2.Clear();
                   }
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
    我想了很久,也没想通应该把调用写在哪里,怎么写,单纯地看C#数据库操作是不能明白怎么做的,而且我是个菜鸟。我已经在SQL数据库里的用户表里编辑了一条数据,现在只要把数据里的密码加密,再修改一下上面的代码就OK了
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Text;namespace TeacherInfo
    {
        class MD5
        {
            #region [函数] [加密]
            public string Fun_Secret(string Send_String)
            {
                byte[] Secret_Byte = UTF8Encoding.UTF8.GetBytes(Send_String);
                string Secret_String = Convert.ToBase64String(Secret_Byte);
                return Secret_String;
            }
            #endregion        #region [函数] [解密]
            public string Fun_UnSecret(string Get_String)
            {
                byte[] UnSecret_Byte = Convert.FromBase64String(Get_String);
                string UnSecret_String = UTF8Encoding.UTF8.GetString(UnSecret_Byte);
                return UnSecret_String;
            }
            #endregion
        }
    }
    调用 MD5 Sc = new MD5();
      Control_name.Text = Sc.Fun_UnSecret(Temp_Data[Data_Num]);
      

  3.   

    上面这个是MD5的加密吧,可能是我注释给你的误导,我要的是DES的
      

  4.   


    唉,百度都是DES类怎么写,没有怎么调用和使用,而且现在我想把数据库里已经存在的数据加密,然后再在登陆的时候验证
      

  5.   

    登录时从数据库取得用户名和密码A
    解密密码得密码B
    用用户名和密码B跟用户输入匹配;保存密码,则先把用户输入的密码P 加密得字符串Q 在数据库对应字段写入Q、、、