欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當前位置:主頁 > 軟件編程 > C#教程 >

C# winform實現(xiàn)登陸次數(shù)限制

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊: 次

我們在網(wǎng)上登陸的時候有些網(wǎng)站在用戶多次輸錯密碼之后會自動把賬戶凍結(jié),不能在進行登陸,小編這次做的winform程序就是要實現(xiàn)這種功能,具體內(nèi)容如下

功能一:根據(jù)數(shù)據(jù)庫字段判斷用戶名和密碼是否匹配;

功能二:如果輸入錯誤自動記錄連續(xù)錯誤次數(shù);

功能三:如果用戶登陸成功之后會自動清除錯誤次數(shù),使用戶仍然可以連續(xù)登陸3次;

首先在winform窗體上拖入兩個label和textbox,textbox分別命名為txbUserName,txbPassWord;然后在拖入一個button按鈕;雙擊button按鈕寫按鈕事件,代碼如下:

private void button1_Click(object sender, EventArgs e)
    {
      using (SqlConnection con = new SqlConnection("server=.; database=text; integrated security=SSPI;"))
      {
        using (SqlCommand com = new SqlCommand())
        {
          com.CommandText = "select * from T_Users where UserName=@username";
          com.Connection = con;
          con.Open();
          com.Parameters.Add(new SqlParameter("username", txbUserName.Text));
          //com.Parameters.Add(new SqlParameter("password", textBox2.Text));
          using (SqlDataReader read = com.ExecuteReader())
          {
            if (read.Read())
            {
              int errortimes = read.GetInt32(read.GetOrdinal("ErrorTimes")); //讀取錯誤登陸次數(shù)
              if (errortimes >= 3)    //判斷錯誤次數(shù)是否大于等于三
              {
                MessageBox.Show("sorry 你已經(jīng)不能再登陸了!");
              }
              else
              {
                string passwored = read.GetString(read.GetOrdinal("PassWord"));
                if (passwored == txbPassWord.Text)
                {
                  MessageBox.Show("登陸成功!");
                  this.qingling();        //登陸成功把錯誤登陸次數(shù)清零
                }
                else
                {
                  MessageBox.Show("登陸失?。?);
                  this.leiji();        //登陸失敗把錯誤登陸次數(shù)加一
                }
              }
            }
          }
        }
      }
    } 

累加錯誤登陸次數(shù)函數(shù):       

public void leiji()
    {
      using (SqlConnection con = new SqlConnection("server=.; database=text; integrated security=SSPI;"))
      {
        using (SqlCommand com = new SqlCommand())
        {
          com.Connection = con;
          com.CommandText = "update T_Users set ErrorTimes=ErrorTimes+1 where UserName=@username";
          com.Parameters.Add(new SqlParameter("username", txbUserName.Text));
          con.Open();
          com.ExecuteNonQuery();
        }
      } 
    }

清零錯誤登陸次數(shù)函數(shù):       

 public void qingling()
    {
      using (SqlConnection con = new SqlConnection("server=.; database=text; integrated security=SSPI;"))
      {
        using (SqlCommand com = new SqlCommand())
        {
          com.Connection = con;
          com.CommandText = "update T_Users set ErrorTimes=0 where UserName=@username";
          com.Parameters.Add(new SqlParameter("username", txbUserName.Text));
          con.Open();
          com.ExecuteNonQuery();
        }
      }
    }

在button事件的代碼中小編使用了using,關(guān)于using的用法與好處在《談C# using的用法與好處》中已經(jīng)寫過。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助。

上一篇:C# WinForm打開PDF文件并在窗體中顯示

欄    目:C#教程

下一篇:C#獲取串口列表實現(xiàn)實時監(jiān)控串口

本文標題:C# winform實現(xiàn)登陸次數(shù)限制

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6533.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有