日本好好热aⅴ|国产99视频精品免费观看|日本成人aV在线|久热香蕉国产在线

  • <cite id="ikgdy"><table id="ikgdy"></table></cite>
    1. 西西軟件園多重安全檢測(cè)下載網(wǎng)站、值得信賴的軟件下載站!
      軟件
      軟件
      文章
      搜索

      首頁(yè)編程開(kāi)發(fā)C#.NET → C#里面如何對(duì)數(shù)據(jù)庫(kù)里面的密碼字段加密

      C#里面如何對(duì)數(shù)據(jù)庫(kù)里面的密碼字段加密

      相關(guān)軟件相關(guān)文章發(fā)表評(píng)論 來(lái)源:本站整理時(shí)間:2010/11/30 22:41:33字體大。A-A+

      作者:佚名點(diǎn)擊:802次評(píng)論:0次標(biāo)簽: 數(shù)據(jù)庫(kù) 字段加密 MD5

      • 類型:學(xué)生模板大小:3.7M語(yǔ)言:中文 評(píng)分:10.0
      • 標(biāo)簽:
      立即下載

      C#里面如何對(duì)數(shù)據(jù)庫(kù)里面的密碼字段加密?加密以后如何在在程序里面取值?

      都是使用MD5加密,推薦一篇文檔給你。有很詳細(xì)的加密和解密方法,還有就是C#中有自帶的加密和解密方法。隨便你使用哪種。

      為什么要解密呢?MD5是可以窮舉破解,但是應(yīng)用中不需要解密,要不然就不安全了。如果你要查找當(dāng)前用戶輸入的密碼是否正確,你加密一下去數(shù)據(jù)庫(kù)里查詢就可以了?

      密碼用md5加密保存到數(shù)據(jù)庫(kù),然后用戶登錄時(shí)你把他的密碼在MD5加密一次跟數(shù)據(jù)庫(kù)里面的比較就行了。

      方法:

      密碼子段類型為binary(50)。應(yīng)用System Security.Cryptography名稱空間下的SHA1類的ComputeHash()方法將字符密碼進(jìn)行哈希散列運(yùn)算轉(zhuǎn)換為byte[]類型對(duì)象,保存入數(shù)據(jù)庫(kù)。
      //哈系散列轉(zhuǎn)換
      publicbyte[] getSaltedPassword(string password)
              {
                  SHA1 sha1
      =SHA1.Create();
      //應(yīng)用System.Text空間下的Unicode.GetBytes方法獲得byte.
                  byte[] bytePassword=sha1.ComputeHash(Encoding.Unicode.GetBytes(password));
                 
      return bytePassword;
              }
      //數(shù)據(jù)存入,直接將byte[]保存入binary字段
      publicint AccountRegister(string accountName,string password,string email)
              {
                 
      byte[] bytePassword =this.getSaltedPassword(password);
                  SqlConnection myConnection
      =new SqlConnection(this.GetConnStr);
                  myConnection.Open();
                  SqlCommand myCommand
      =new SqlCommand("Account_Add",myConnection);
                  myCommand.CommandType
      =CommandType.StoredProcedure;
                  SqlParameter prmAccountName
      =myCommand.Parameters.Add(new SqlParameter("@AccountName",SqlDbType.VarChar,50));
                  prmAccountName.Value
      =accountName;
                  SqlParameter prmPassword
      =myCommand.Parameters.Add(new SqlParameter("@password",SqlDbType.Binary,50));
                  prmPassword.Value
      =bytePassword;
                  SqlParameter prmEmail
      =myCommand.Parameters.Add(new SqlParameter("@email",SqlDbType.VarChar,50));
                  prmEmail.Value
      =email;
                 
      int myInt=myCommand.ExecuteNonQuery();
                  myCommand.Dispose();
                  myConnection.Close();
                 
      return myInt;
              }
      //密碼比較。將字符密碼轉(zhuǎn)換為哈西散列后直接與數(shù)據(jù)庫(kù)binary密碼字段比較
      publicint AccountVerify(string accountName,string password)
              {
                 
      byte[] bytePassword =this.getSaltedPassword(password);
                  SqlConnection myConnection
      =new SqlConnection(this.GetConnStr);
                  myConnection.Open();
                  SqlCommand myCommand
      =new SqlCommand("Account_Check",myConnection);
                  myCommand.CommandType
      =CommandType.StoredProcedure;
                  SqlParameter prmAccountName
      =myCommand.Parameters.Add(new SqlParameter("@AccountName",SqlDbType.VarChar,50));
                  prmAccountName.Value
      =accountName;
                  SqlParameter prmPassword
      =myCommand.Parameters.Add(new SqlParameter("@password",SqlDbType.Binary,50));
                  prmPassword.Value
      =bytePassword;
                  SqlParameter prmReturnValue
      =myCommand.Parameters.Add(new SqlParameter("@Return_Value",SqlDbType.Int,4));
                  prmReturnValue.Direction
      =ParameterDirection.ReturnValue;
                  myCommand.ExecuteNonQuery();
                 
      int accountID=(int)prmReturnValue.Value;
                  myCommand.Dispose();
                  myConnection.Close();
                 
      return accountID;
              }
      //相關(guān)Store procedure
      //登陸驗(yàn)證
      CREATE PROCEDURE Account_Check @AccountName varchar(50),@Password binary(50)
      AS
        Declare @AccountId
      int
          Select @AccountId
      = AccountID From Accounts
                     Where accountName
      =@accountname;
           If isnull(@AccountID,
      0)=0    
              Select @AccountId
      =-1--//賬號(hào)錯(cuò)誤!   
          Else
             Begin
                 Select @accountID
      =null
                 Select @AccountId
      = AccountID From Accounts
                             Where accountName
      =@accountname and password=@password;
                 If isnull(@AccountID,
      0)=0
                   Select @AccountID
      =0; --//密碼錯(cuò)誤!     
            End 
      Return @AccountID;
      //用戶增加
      CREATE PROCEDURE Account_Add @accountName varchar(50),@password binary (50),@email varchar(50)
         AS
          insert into Accounts(accountName,password,email)
                      values(@accountName,@password,@email);
         
      return @@Error;

      FormsAuthentication.HashPasswordForStoringInConfigFile(this.TextBox2.Text, "md5");//使用MD5加密

      不解密就MD5,sha-1這類hash加密,解密的話,自己寫加密算法。。。

        讀書(shū)筆記
        (95)讀書(shū)筆記
        書(shū)中自有黃金屋,書(shū)中自有顏如玉,我們總能從書(shū)中學(xué)習(xí)到很多意想不到的知識(shí),看見(jiàn)不一樣的風(fēng)景。特別是在我們的學(xué)生時(shí)代,不僅是教科書(shū),更要涉及各種各樣的課外書(shū)籍,不僅要讀,還要學(xué)會(huì)做讀書(shū)筆記。我們讀再多,不做讀書(shū)筆記,沒(méi)有讀后感,也相當(dāng)于白讀,做讀書(shū)筆記的過(guò)程就相當(dāng)于仔細(xì)品讀的過(guò)程,而不是一目十行的略讀。本合集是由西西為大家整理的讀書(shū)筆記合集,歡迎有需要的朋友前來(lái)下載。讀書(shū)筆記怎么寫讀書(shū)筆記是人們?cè)谧x書(shū)...更多>>

        相關(guān)評(píng)論

        閱讀本文后您有什么感想? 已有人給出評(píng)價(jià)!

        • 8 喜歡喜歡
        • 3 頂
        • 1 難過(guò)難過(guò)
        • 5 囧
        • 3 圍觀圍觀
        • 2 無(wú)聊無(wú)聊

        熱門評(píng)論

        最新評(píng)論

        發(fā)表評(píng)論 查看所有評(píng)論(0)

        昵稱:
        表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
        字?jǐn)?shù): 0/500 (您的評(píng)論需要經(jīng)過(guò)審核才能顯示)