任何人都可以帮助解决我遇到的一些问题。我正在尝试创建一种自制的身份验证方法,我陷入了一些领域,并希望有人能提供帮助。我想问的第一件事是如何解决我在代码中评论的问题:
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
}