public async Task <User> Login(string email, string password) { var items = await _dbService.FindItems(Collections.Users, "email", email); if (items.Count > 1) { Log.Error("Found several ambigous results when looking for users!"); } var item = items.FirstOrDefault(); if (item == null) { Log.Info("Found no users to log in"); return(null); } string value = item.GetValue("password").ToString(); if (string.IsNullOrEmpty(value)) { Log.Error("Could not cast password to string or it password doesnt exist!"); return(null); } if (!password.Equals(value)) { Log.Info("User entered the wrong password."); return(null); } User user = new User(); try { user.FirstName = (string)item.GetValue("firstName"); user.LastName = (string)item.GetValue("lastName"); } catch (Exception ex) { Log.Error("Couldnt create user from BSON document during login.", ex); return(null); } Log.Info("User entered the correct password."); return(user); }