C#密码DES加密,将加密后的数据存到数据库里 DES加密和MD5完全不是一回事,你代码里全混了。MD5也不是加密。数据库保存密码的MD5值。用户登录时,输入的密码也做MD5,然后和数据库里的比较是否一致即可。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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了 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]); 上面这个是MD5的加密吧,可能是我注释给你的误导,我要的是DES的 唉,百度都是DES类怎么写,没有怎么调用和使用,而且现在我想把数据库里已经存在的数据加密,然后再在登陆的时候验证 登录时从数据库取得用户名和密码A解密密码得密码B用用户名和密码B跟用户输入匹配;保存密码,则先把用户输入的密码P 加密得字符串Q 在数据库对应字段写入Q、、、 IC卡通不过密码验证 C# 如何在后台实现多语言切换,思路即可 关于画板的问题 C#按钮长按 VS2005 c# web 中用什么控件 来 显示GIF图片,我用 Image控件 显示 的GIF图片不会动? 一个关于复合控件的问题 DevExpress的GridControl如何控制展开全部的行 求教有关登陆验证弹出信息框的问题~~~~~~~`` IDE中的SQL调试 关于迭代器和泛型的问题,我也不知道怎么回事求大神帮忙看下。 datagrid提取选中行的数据,对于老手这简直是白送金币啊~!主要还是表示无尽的感谢~! 【求助】C# 通过处理xml文以及其对应的xsd文件生成一张二维表格
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了
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]);
唉,百度都是DES类怎么写,没有怎么调用和使用,而且现在我想把数据库里已经存在的数据加密,然后再在登陆的时候验证
解密密码得密码B
用用户名和密码B跟用户输入匹配;保存密码,则先把用户输入的密码P 加密得字符串Q 在数据库对应字段写入Q、、、