2011-05-06 60 views
0

我使用VB.NET 2010FormsAuthentication未聲明

我的一個行代碼是:

Encoding.UTF8.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox_AccessCode.Text, "MD5")) 

但FormsAuthentication有下劃線且錯誤寫着「FormsAuthentication」未聲明。我已確保System.Web.Security命名空間已導入,但我仍然收到該消息。

任何想法?

謝謝。

+0

什麼項目類型? Asp.Net? – 2011-05-06 05:25:59

+0

只是一個Windows窗體應用程序。 – Brady 2011-05-06 06:25:52

回答

0

FormsAuthentication形成了在asp.net中使用的System.Web的一部分,並且無法通過Win Forms訪問。不能完全肯定,如果你將能夠導入DLL和使用它的方式,我對此表示懷疑......

如果你只是想哈希MD5字符串,你可以做如下:

new System.Security.Cryptography.MD5CryptoServiceProvider(); 
byte[] bs = System.Text.Encoding.UTF8.GetBytes(TextBox_AccessCode.Text); 
x.ComputeHash(bs); 
+0

感謝您的信息,但這不適用於VB.NET。 – Brady 2011-05-06 19:30:47

0

謝謝到TBohnen.jnr,我發現表單身份驗證不是通過VB.NET的Windows窗體的一部分。我結束了使用下面的代碼生成一個MD5哈希:

Public Shared Function MD5(ByVal str As String) As String 
    Dim provider As MD5CryptoServiceProvider 
    Dim bytValue() As Byte 
    Dim bytHash() As Byte 
    Dim strOutput As String = "" 
    Dim i As Integer 
    provider = New MD5CryptoServiceProvider() 
    bytValue = System.Text.Encoding.UTF8.GetBytes(str) 
    bytHash = provider.ComputeHash(bytValue) 
    provider.Clear() 
    For i = 0 To bytHash.Length - 1 
     strOutput &= bytHash(i).ToString("x").PadLeft(2, "0") 
    Next 
    Return strOutput 
End Function