2013-12-11 85 views
0

我不敢使用用戶表單數據來查詢用戶登錄數據庫,因爲公司只有20名員工,我在想這個功能,但我不確定這是否仍然是易代碼破解任何沒有這麼好的黑客用戶用戶名和用戶密碼驗證功能

Private Function VerifyCredentials(ByVal User As String, ByVal Password As String) As Boolean 


    Dim verification As Boolean = False 
    Dim _conString As String = WebConfigurationManager.ConnectionStrings 
("YounnectionString").ConnectionString 

    'Initialize connections variables 
    Dim cnn As New SqlConnection(_conString) 
    Dim cmd As New SqlCommand 
    cmd.Connection = cnn 
    cnn.Open() 

    'No data from the form are used on the SQL Server 
    cmd.CommandText = "Select UserName, UserPassword from tblUsers;" 

    Dim cmdReader As SqlDataReader = cmd.ExecuteReader() 

    'compare the data from the server with the data from the form, it so not matter what the user send from the form 
    While cmdReader.Read() 
     If Trim(User) = Trim(cmdReader("UserName")) 
     AndAlso Trim(Password) = Trim(cmdReader("UserPassword")) Then 
      verification = True 
     End If 
    End While 
    ' this method may result on performance problems if your tblUsers is too big, 
'afther all it is the entrance and most of the companies 
'just has several hundred users 
    cmdReader.Close() 
    cmd.CommandText = "" 
    cnn.Close() 

    Return verification 

End Function 

請有人檢查這個代碼給我更好的解決方案,該公司是黑客的人與開發商被解僱了。我不知道安全性,但他們想聘請專家解決方案。感謝

+0

請刪除您代碼並實現ASP。 NET身份解決方案。 http://blogs.msdn.com/b/webdev/archive/2013/06/27/introducing-asp-net-identity-membership-system-for-asp-net-applications.aspx –

+0

感謝您的快速回答 – user295454

回答

0

你只是存儲明文密碼。一旦數據庫被破壞,你沒有時間通知用戶。

您需要存儲帶鹽的散列密碼。雖然它仍然可以被破解(這需要很多時間),但您仍然需要通知用戶更改密碼。

對於ASP.Net,最簡單的方法將使用

  1. ASP.NET Universal Providers
  2. ASP.NET Identity
+0

謝謝,我會檢查 – user295454

0

讓數據庫過濾器爲您服務。 查詢更改爲

"Select UserName, UserPassword from tblUsers 
WHERE UserName = " & Trim(User) & " AND UserPassword = " & Trim(Password) 

然後,如果有一些結果驗證是正確的,如果沒有結果,obviusly你必須返回false,所以根本就

Return cmdReader.Read() 
+0

這個代碼是這樣的,這就是爲什麼(我猜)得到破解,因爲它是發送用戶表單數據到查詢..謝謝任何方式Nahuel – user295454

+1

@ user295454 ***不要使用此代碼。它會導致你到[SQL注入攻擊](http://en.wikipedia.org/wiki/SQL_injection)。相反,你想使用[參數化查詢](http://www.dotnetperls.com/sqlparameter)。*** – Win

+0

感謝贏得了建議 – user295454