/// <summary>
///与登入界面有关的集合在这里,ExecuteQuery方法在https://blog.csdn.net/yunduanzhijie/article/details/98488594
/// </summary>
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Button1_Click_1(object sender, EventArgs e)
{
DataTable d1 = new DataTable();
String name = this.textBox2.Text; // 获取里面的值
String password = this.textBox1.Text;
Form2 f2 = new Form2();
//查询并判断用户名是否存在
string sql_select = "SELECT password FROM [study-userset] where username='" + name + "'";
d1=f2.ExecuteQuery(sql_select);
if (d1.Rows.Count>0)
{
string pw = d1.Rows[0]["password"].ToString();
if (f2.ComputeMD5Hash(password).Equals(pw)) // 判断账号密码是否相同
{
MessageBox.Show("登录成功!");
}
else
{
MessageBox.Show("密码错误!");
}
}
else
{
MessageBox.Show("未取得用户名!");
}
}
private void TextBox1_Enter(object sender, EventArgs e)
{
//改变活动时的样式
textBox1.ForeColor = Color.Black;
textBox1.BackColor = Color.Gainsboro;
}
private void TextBox1_Leave(object sender, EventArgs e)
{
textBox1.ForeColor = Color.Gainsboro;
textBox1.BackColor = Color.White;
}
private void TextBox2_Enter(object sender, EventArgs e)
{
textBox2.ForeColor = Color.Black;
textBox2.BackColor = Color.Gainsboro;
}
private void TextBox2_Leave(object sender, EventArgs e)
{
textBox2.ForeColor = Color.Gainsboro;
textBox2.BackColor = Color.White;
}
private void Button1_Click_2(object sender, EventArgs e)
{
//关闭、打开页面
Form1 f = new Form1();
Form2 f2 = new Form2();
f2.Show();
f.Close();
}
}
登入界面:从数据库中获取信息验证登入(与注册界面相联系)
最新推荐文章于 2024-01-13 14:56:29 发布