Can anyone help with some problems I have. I am trying to create an self made authentication method, im abit stuck in a few areas and was hoping some one could help. First thing I would like to ask is how to solve the problem I have commented in the code:
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
}
“Cannot be used like a method” is likely because you added brackets:
result.Password()if it is a property drop the bracketsresult.Password. Adding the brackets makes the compiler attempt to compile it as a method call when in fact it is a property or field.The second error is you are trying to return
students, which is a list of students. The method requires astringas a return value. Did you mean to insteadreturn result.StudentID;? The exception is detailing the failed attempt at compiling the cast fromList<Student>tostring.I cannot offer any advice on the second half of your questions.
Update
You are expected to find a method called
SequenceEqualonbyte[]. This is a Linq extension method so you may need to add:using System.Linq;To the top of your file.
You will then likely get an error trying to pass a string to this method:
SequenceEqual(result.Password);.