2012-04-24 34 views
1

任何人都可以幫助我解決一些問題。我正在嘗試創建一個自制的身份驗證方法,我只是在幾個方面陷入困境,並希望有人能夠提供幫助。我想問的第一件事是如何解決我在代碼註釋的問題:byte []不包含SequenceEqual認證方法的定義

public string Authentication(string studentID, string password) 
    { 
     var result = students.FirstOrDefault(n => n.StudentID == studentID); 
     //find the StudentID that matches the string studentID 
     if (result != null) 
     //if result matches then do this 
     { 
      //---------------------------------------------------------------------------- 
      byte[] passwordHash = Hash(password, result.Salt); 
      string HashedPassword = Convert.ToBase64String(passwordHash); 
      //---------------------------------------------------------------------------- 
      // take the specific students salt and generate hash/salt for string password (same way student.Passowrd was created) 

      System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); 
      byte[] UserPassword = enc.GetBytes(HashedPassword); 
      UserPassword.SequenceEqual(result.Password); // byte[] does not contain a definition for SequenceEqual? 
      //check if the HashedPassword (string password) matches the stored student.Password 
     } 
     return result.StudentID; 
     //if string password(HashedPassword) matches stored hash(student.Passowrd) return student list 


     //else return a message saying login failed 
    } 

回答

2

「不能等的方法可以使用」可能是因爲您添加括號:result.Password(),如果它是一個屬性掉落括號result.Password。添加括號使得編譯器試圖將它編譯爲方法調用,而實際上它是一個屬性或字段。

第二個錯誤是你試圖返回students,這是一個學生列表。該方法需要string作爲返回值。你的意思是改爲return result.StudentID;?這是一個例外,詳細說明了在編制演員時從List<Student>string的失敗嘗試。

我無法就您的問題的後半部分提供任何建議。

更新

我們希望你找到一個方法上byte[]SequenceEqual。這是一個LINQ擴展方法,所以你可能需要添加:

using System.Linq;

到文件的頂部。

然後,您可能會嘗試將字符串傳遞給此方法:SequenceEqual(result.Password);

+0

AHHH賓果上返回result.StudentID解決了,如果我刪除括號tho整行是錯誤的 – 2012-04-24 09:07:56

+0

它說byte []不包含序列相等?下半場我可能會弄清楚,如果我得到了第一點的工作。只是想展示我的想法。 – 2012-04-24 09:10:06

+0

@JungleBoogie聽起來像是下一個錯誤。我無法幫助。用示範問題的示例創建一個新問題。 – 2012-04-24 09:10:52

相關問題