C#——WinForm修改密码

2020-11-28 06:43

阅读:524

标签:winform   style   blog   class   c   code   

soscw.com,搜素材

  1 private void button2_Click(object sender, EventArgs e)
  2         {
  3             //button2 : “确认”按钮
  4             //修改密码
  5             if (textBox1.Text == "")
  6             {
  7                 MessageBox.Show("请输入原密码");
  8             }
  9             else if (textBox2.Text == "")
 10             {
 11                 MessageBox.Show("请输入新密码");
 12             }
 13             else if (textBox3.Text == "")
 14             {
 15                 MessageBox.Show("请确认新密码");
 16             }
 17             else if (textBox4.Text == "")
 18             {
 19                 MessageBox.Show("请输入验证码");
 20             }
 21             else if (textBox4.Text.Trim() != label5.Text)
 22             {
 23                 MessageBox.Show("验证码输入错误");
 24                 label5_Click(null, null);  //调用label5_Click事件
 25                 textBox4.Text = "";
 26             }
 27             else
 28             {
 29                 MyConnection conn = new MyConnection();    //数据库地址自己写
 30                 SqlConnection myCon = conn.GetConnection();
 31                 SqlCommand myCom = myCon.CreateCommand();
 32                 myCom.CommandText = "select 密码 from Table_用户 where 学号=‘" + PublicData.id + "";                                //具体的字段名和表名自己改变
 33                 SqlDataAdapter myAdapter = new SqlDataAdapter();
 34                 myAdapter.SelectCommand = myCom;
 35                 DataSet mySet = new DataSet();
 36                 string yuanmima = myAdapter.Fill(mySet, "Table_用户").ToString();
 37                 if (textBox1.Text != yuanmima)
 38                 {
 39                     MessageBox.Show("原密码错误,请重新输入", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
 40                     textBox1.Text = "";
 41                     textBox1.Focus();
 42                 }
 43                 else
 44                 {
 45                     if (textBox2.Text.Trim() != textBox3.Text.Trim())
 46                     {
 47                         MessageBox.Show("两次输入的密码不一致,请重新输入!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
 48                         textBox2.Text = "";
 49                         textBox3.Text = "";
 50                         textBox2.Focus();
 51                     }
 52                     else
 53                     {
 54                         SqlCommand myCom1 = myCon.CreateCommand();
 55                         myCom1.CommandText = "update Table_用户 set 密码=‘" + textBox2.Text + "‘ where 学号=‘" + PublicData.id + "";
 56                         myCon.Open();
 57                         myCom1.ExecuteNonQuery();
 58                         myCom1.Dispose();
 59                         myCon.Close();
 60                         MessageBox.Show("修改成功!");
 61                     }
 62                 }
 63             }
 64         }
 65 
 66         private void label5_Click(object sender, EventArgs e)
 67         {
 68             //生成随机验证码
 69             string VcArray = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
 70             string[] yanzhenma = VcArray.Split(,);
 71             string VNum = "";
 72             Random rand = new Random();
 73             for (int i = 0; i 4; i++)
 74             {
 75                 int t = rand.Next(61);
 76                 VNum += yanzhenma[t];
 77             }
 78             label5.Text = VNum;
 79 
 80             #region(生成随即验证码字体)
 81             Random z = new Random();
 82             int zi = z.Next(8);
 83             switch (zi)
 84             {
 85                 case 0:
 86                     label5.Font = new Font("华文彩云", label5.Font.Size, label5.Font.Style | FontStyle.Bold);
 87                     break;
 88                 case 1:
 89                     label5.Font = new Font("华文行楷", label5.Font.Size, label5.Font.Style | FontStyle.Bold);
 90                     break;
 91                 case 2:
 92                     label5.Font = new Font("宋体", label5.Font.Size, label5.Font.Style | FontStyle.Bold);
 93                     break;
 94                 case 3:
 95                     label5.Font = new Font("方正舒体", label5.Font.Size, label5.Font.Style | FontStyle.Bold);
 96                     break;
 97                 case 4:
 98                     label5.Font = new Font("华文彩云", label5.Font.Size, label5.Font.Style);
 99                     break;
100                 case 5:
101                     label5.Font = new Font("华文行楷", label5.Font.Size, label5.Font.Style);
102                     break;
103                 case 6:
104                     label5.Font = new Font("宋体", label5.Font.Size, label5.Font.Style);
105                     break;
106                 case 7:
107                     label5.Font = new Font("方正舒体", label5.Font.Size, label5.Font.Style);
108                     break;
109             }
110             #endregion
111 
112             #region(生成随即验证码字体大小)
113             Random d = new Random();
114             int daxiao = z.Next(8);
115             switch (daxiao)
116             {
117                 case 0:
118                     label5.Font = new Font(label5.Font.FontFamily, 7, label5.Font.Style);
119                     break;
120                 case 1:
121                     label5.Font = new Font(label5.Font.FontFamily, 8, label5.Font.Style);
122                     break;
123                 case 2:
124                     label5.Font = new Font(label5.Font.FontFamily, 9, label5.Font.Style);
125                     break;
126                 case 3:
127                     label5.Font = new Font(label5.Font.FontFamily, 10, label5.Font.Style);
128                     break;
129                 case 4:
130                     label5.Font = new Font(label5.Font.FontFamily, 11, label5.Font.Style);
131                     break;
132                 case 5:
133                     label5.Font = new Font(label5.Font.FontFamily, 12, label5.Font.Style);
134                     break;
135                 case 6:
136                     label5.Font = new Font(label5.Font.FontFamily, 13, label5.Font.Style);
137                     break;
138                 case 7:
139                     label5.Font = new Font(label5.Font.FontFamily, 14, label5.Font.Style);
140                     break;
141             }
142             #endregion
143 
144         }
soscw.com,搜素材

soscw.com,搜素材

C#——WinForm修改密码,搜素材,soscw.com

C#——WinForm修改密码

标签:winform   style   blog   class   c   code   

原文地址:http://www.cnblogs.com/paomoopt/p/3737566.html


评论


亲,登录后才可以留言!