I get an error not all code paths return a value?
public string Authentication(string studentID, string password) // this line? { 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) if (HashedPassword == result.Password) //check if the HashedPassword (string password) matches the stored student.Password { return result.StudentID; // if it does return the Students ID } } else //else return a message saying login failed { return "Login Failed"; } }
Login Failedwith student ids. You could usenullas return value for failure, or change the return type to something more complex, perhaps some kind of discriminating union.Login Failedas a string, you should rather returnnull, or a complex type that says whether logging in was successful or not, along with the student's ID (ornull).